Hola joaowizard,
gracias por tus consejos del focus, lo itentare poner, pero más adelante, pues ya he puesto lo que me has dicho arriba de formulario.php
<?php session_start(); ?>
pero me da el error:
Código Error:
Ver originalsession_start() [function.session-start] Cannot send session cache limiter - headers already sent (output started at home/formfull/procesa.php) on line 1
Además he observado que el email siempre lo envia este validado o no.
Es decir si yo soy un usuario y le doy a enviar, y luego sale el Alert y por ejemplo cancelo, aun así el formulario me lo envia aunque sea vacio.
Agradezco mucho tu ayuda. Te paso de nuevo los formularios
Código PHP:
<?php session_start(); ?>
<html><head><title>formulario</title></head>
<body>
<form name="ejemplo" action="procesa.php" method="post">
<p>Nombre: <input type="text" name="nombre">(obligatorio)</p>
<p>email: <input type="text" name="email">(obligatorio)</p>
<p>Habilidades:<input type="radio" name="karate">Baloncesto <input type="radio" name="karate">Karate <input type="radio" name="karate">Futbol (obligatorio)</p>
<p>Aceptas las condiciones: <input type="checkbox" name="aceptas">Si(obligatorio)</p>
<p>ciudad: <select name="ciudad" size="1">
<option>Barcelona</option>
<option>Madrid</option>
<option>Sevilla</option>
</select>(obligatorio)</p>
<p>Comentarios: <textarea name="comentarios" rows="2"></textarea>(obligatorio)</p>
<p><img src="captcha.php" width="100" height="30"></p>
<p><input name="tmptxt" type="text">
(obligatorio)</p>
<p>
<label>
<input type="submit" name="button" id="button" value="Enviar">
</label>
</p>
</form>
</body>
Procesa.php
Código PHP:
<?php session_start();//verifico captcha
if ($_SESSION['tmptxt'] != $_POST['tmptxt']) {
echo "<script>window.alert('IMAGEN DE SEGURIDAD INVALIDA');</script>;";;//mensaje de error correspondiente
echo "<script>location.href='javascript:history.back()' ;</script>;";//con esto no se pierden los datos del FORM
}
//**************** COMPRUEBO NOMBRE VACIO **********************
if (!($_POST['nombre'])){
echo "<script>window.alert('Debe llenar el campo Nombre');</script>;";
echo "<script>location.href='javascript:history.back()' ;</script>;";
}
//**************** COMPRUEBO EMAIL VACIO Y VALIDO **********************
if (!($_POST['email'])){
echo "<script>window.alert('Debe llenar el campo Email');</script>;";
echo "<script>location.href='javascript:history.back()' ;</script>;";
}
elseif(!eregi("^[a-z0-9]+([_\\.-][a-z0-9]+)*" ."@"."([a-z0-9]+([\.-][a-z0-9]+)*)+"."\\.[a-z]{2,}"."$",$_POST['email'])){
echo "<script>window.alert('El email ingresado es invalido');</script>;";
echo "<script>location.href='javascript:history.back()' ;</script>;";
//acá verifico que el email sea VALIDO, que tenga la forma [email][email protected][/email]
}
//**************** COMPRUEBO RADIO BOTON MARCADO **********************
if (!($_POST['karate'])){
echo "<script>window.alert('Debe llenar el campo Habilidades Radio buton');</script>;";
echo "<script>location.href='javascript:history.back()' ;</script>;";
}
//**************** COMPRUEBO si aceptas las condiciones **********************
if (!($_POST['aceptas'])){
echo "<script>window.alert('Debe llenar el campo Aceptar las condiciones');</script>;";
echo "<script>location.href='javascript:history.back()' ;</script>;";
}
//**************** COMPRUEBO ciudad **********************
if (!($_POST['ciudad'])){
echo "<script>window.alert('Debe llenar el campo ciudad');</script>;";
echo "<script>location.href='javascript:history.back()' ;</script>;";
}
//**************** COMPRUEBO comentarios MARCADO **********************
if (!($_POST['comentarios'])){
echo "<script>window.alert('Debe llenar el campo comentarios');</script>;";
echo "<script>location.href='javascript:history.back()' ;</script>;";
}
//una vez que verifique todo, pues envÃ*o el email.
//Declaras hacia donde se envÃ*a el correo, el Destinatario
$recipiente = "[email protected]";
//defines el Asunto del correo
$asunto = "Contacto desde la Pagina WEB ";
//defines el cuerpo del mensaje
$message ="nombre: ".$_POST['nombre']."<br>";
$message .="email: ".$_POST['email']."<br>";
$message .="preferencias: ".$_POST['karate']."<br>";
$message .="ciudad: ".$_POST['ciudad']."<br>";
$message .="comentarios: ".$_POST['comentarios']."<br>";
$message = stripslashes($message);
//haces los encabezados
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type:text/html; charset=iso-8859-1\r\n";
$headers .= "From: $email\r\n";
$headers .= "Repaly-to: $email\r\n";
$headers .= "Cc: ".$_POST['email']."\r\n";//le envÃ*as una copia al remitente
//chao email!!
mail($recipiente,$asunto,$message,$headers);
echo "El mensaje se envio correctamente";
?>