Ver Mensaje Individual
  #4 (permalink)  
Antiguo 12/11/2011, 21:56
Avatar de javier_del_castillo
javier_del_castillo
 
Fecha de Ingreso: noviembre-2011
Mensajes: 4
Antigüedad: 12 años, 5 meses
Puntos: 1
Respuesta: validando un checkbox

Saludos... te ayudo con un ejemplo...
El formulario html tiene el siguiente código:
<head>
<title>Problema</title>
</head>
<body>
<form action="pagina2.php"
method="post">
Ingrese primer valor:
<input type="text" name="valor1">
<br>
Ingrese segundo valor:
<input type="text" name="valor2">
<br>
<input type="checkbox" name="check1">sumar
<br>
<input type="checkbox" name="check2">restar
<br>
<input type="submit" name="operar">
</form>
</body>
</html>

Ahora veamos el código de la página que procesa el formulario:
<html>
<head>
<title>Problema</title>
</head>
<body>
<?php
if (isset($_REQUEST['check1']))
{
$suma=$_REQUEST['valor1'] + $_REQUEST['valor2'];
echo "La suma es:".$suma."<br>";
}
if (isset($_REQUEST['check2']))
{
$resta=$_REQUEST['valor1'] - $_REQUEST['valor2'];
echo "La resta es:".$resta;
}
?>
</body>
</html>