Ver Mensaje Individual
  #5 (permalink)  
Antiguo 21/11/2014, 14:36
kike2lucas
 
Fecha de Ingreso: octubre-2007
Mensajes: 91
Antigüedad: 16 años, 6 meses
Puntos: 1
Respuesta: Duda con validación de formulario

<? if (isset ($_POST["submit_reg"])){
//obtención de variables
$name = $_POST ["name"];
$surname = $_POST ["surname"];

//variables para comparar strings
$text="/^[a-zA-ZñÑáéíóúÁÉÍÓÚäëïöüÄËÏÖÜàèìòùÀÈÌÒÙ\s]+$/";

//funcion que comprueba los datos comparando con las variables de arriba
function checkname ($var, $var2){
$error =false;
if ( !preg_match($var, $var2) || strlen($var2) <= 2) {
$error=true;
}
return $error;
}

$errorname = checkname ($text, $name);
$errorsurname = checksurname ($text, $surname);
}

?>


<? if (!isset ($_POST["submit_reg"]) || $errorname==true || $errorsurname==true){?>
<form action="register_2.php" method="POST">
<label for="name">Nombre </label>
<input name="name" id="name" type="text" class="" value="" />
<p>&nbsp; <? if (isset($errorname) && $errorname==true) {
echo " <font color='#ff0000'>El nombre ingresado no es válido </font><br>";
}?></p>

<label for="surname">Apellido</label>
<input name="surname" id="surname" type="text" class="" value="" />
<p>&nbsp; <? if (isset($errorsurname) && $errorsurname==true) {
echo " <font color='#ff0000'>El apellido ingresado no es válido </font><br>";
}?></p>


<input type="submit" name="submit_reg" value="Registrarse" class="register" />

</form>
<? }?>