Ver Mensaje Individual
  #7 (permalink)  
Antiguo 20/05/2013, 15:13
Avatar de bulter
bulter
 
Fecha de Ingreso: enero-2008
Mensajes: 137
Antigüedad: 16 años, 4 meses
Puntos: 20
Respuesta: campos con validacion

Bueno la verdad es que no suelo dar asi los codigos sin que el user de algo de si , pero tuve buen dia asi :>

Código HTML:
Ver original
  1. <h2>Para leer Hermanos Bladimir debes suscribirte: </h2>
  2. <form id="form1" name="form1" method="post" action="procesar.php">
  3.     <label>
  4.         <p>Ingresa tu E-mail:<br /></p>
  5.     </label>
  6.     <input name="email" type="text" id="email" size="40" />
  7.     <p>
  8.         <input type="submit" name="Submit" value="Enviar" />
  9.     </p>
  10.     <p>
  11.         He leído y acepto los <a href="tyc.html">Términos y Condiciones</a>
  12.         <input name="tyc" type="checkbox" id="tyc" class="">
  13.     </p>
  14. </form>

Código PHP:
function emailValidation($email$hostConnectionVerification false)
{
    if(
$email == null || $email == "" || !is_string($email))
    {
        throw new 
InvalidArgumentException("emailValidation first parameter must be string, and it cannot be empty.");
    }
    
    
preg_match("/^([a-zA-Z0-9&\'\.\-_\+]+)\@([a-zA-Z0-9.-]+\.+[a-zA-Z]{2,6})$/"$email$regExpEmailResult);
    
    if(
filter_var($emailFILTER_VALIDATE_EMAIL) && isset($regExpEmailResult[0], $regExpEmailResult[2]))
    {
        if(
$hostConnectionVerification == true)
        {
            if (
checkdnsrr($regExpEmailResult[2], 'MX') || checkdnsrr($regExpEmailResult[2], 'A')) 
            {
                return 
true;
            }
        }
        
        return 
true;
    }    
    
    return 
false;
}

$email = isset($_POST["email"]) ? $_POST["email"] : null;
$tyc = isset($_POST["tyc"]) ? $_POST["tyc"] : null;

if(
$email != null && $tyc == "on" && emailValidation($email))
{
    echo 
"TODO OK";
}
else
{
    echo 
"ERROR ";
}

?> 
Espero que te sirva.

Saludos