Ver Mensaje Individual
  #22 (permalink)  
Antiguo 03/10/2009, 14:54
manupalaya
 
Fecha de Ingreso: enero-2007
Mensajes: 156
Antigüedad: 18 años
Puntos: 3
Respuesta: Formulario Completo

Ahora si!

bueno al menos ya veo el formulario con su Captcha y todo.

Lo unico que no fuciona son:
- La validacion
- Tampoco me envial el email al usuario, ni a mi
- una pregunta, no se para que es lo de "Vericar codigo"?

Ya queda menos, muchas gracias

Por cierto como ha habido confusiones, escribo el codigo de todos los archivos a continuacion, tal y como me funciona de momento:

Código formulario.php:
Ver original
  1. <form name="ejemplo" action="procesa.php">
  2. <p>Nombre: <input type="text" name="Nombre">(obligatorio)</p>
  3. <p>Email: <input type="text" name="email">(obligatorio)</p>
  4. <p><input type="radio" name="karate">Baloncesto <input type="radio" name="karate">Karate <input type="radio" name="karate">Futbol &nbsp;(obligatorio)</p>
  5. <p>Aceptas las condiciones: <input type="checkbox" name="A">Si&nbsp;&nbsp;&nbsp;(obligatorio)</p>
  6. <p>Ciudad: <select name="ciudad" size="1">
  7. <option>Barcelona</option>
  8. <option>Madrid</option>
  9. <option>Sevilla</option>
  10. </select>(obligatorio)</p>
  11. <p>Comentarios: <textarea name="comentarios" rows="2"></textarea>(obligatorio)</p>
  12. <p><img src="captcha.php" width="100" height="30"></p>
  13. <p><input name="tmptxt" type="text">
  14. (obligatorio)</p>
  15. <p><input name="btget" type="submit" value="Verificar Codigo"></p>
  16.  
  17. <p>
  18. <label>
  19. <input type="submit" name="button" id="button" value="Enviar">
  20. </label>
  21. </p>
  22. </form>

Código captcha.php:
Ver original
  1. <?php session_start();
  2. function captcha($length) {
  3. $pattern = "1234567890abcdefghijklmnopqrstuvwxyz";
  4. for($i=0;$i<$length;$i++) {
  5. $key .= $pattern{rand(0,50)};
  6. }
  7. return $key;
  8. }
  9.  
  10.  
  11. $_SESSION['tmptxt'] = captcha(8);
  12. $captcha = imagecreatefromgif("fondocaptcha.gif");
  13. $colText = imagecolorallocate($captcha, 0, 0, 0);
  14. imagestring($captcha, 5, 16, 7, $_SESSION['tmptxt'], $colText);
  15. header("Content-type: image/gif");
  16. imagegif($captcha);
  17. ?>

Código procesa.php:
Ver original
  1. <?php session_start();//verifico captcha
  2. if ($_SESSION['tmptxt'] != $_POST['tmptxt']) {
  3. echo "<script>alert(Codigo CAPTCHA INVALIDO)</script>";//mensaje de error correspondiente
  4. echo "<script>location.href=javascript:history.back ()</script>";//con esto no se pierden los datos del FORM
  5. }
  6. exit;
  7. //**************** COMPRUEBO NOMBRE VACIO **********************
  8. if (!($_POST['nombre'])){
  9. echo "<script>alert(No deje nombre vacio)</script>";
  10. echo "<script>location.href=javascript:history.back ()</script>";
  11. exit;
  12. }
  13.  
  14. //**************** COMPRUEBO EMAIL VACIO Y VALIDO **********************
  15. if (!($_POST['email'])){
  16. echo "<script>alert(No deje email vacio)</script>";
  17. echo "<script>location.href=javascript:history.back ()</script>";
  18. exit;
  19. }elseif(!eregi("^[a-z0-9]+([_\\.-][a-z0-9]+)*" ."@"."([a-z0-9]+([\.-][a-z0-9]+)*)+"."\\.[a-z]{2,}"."$",$_POST['email'])){
  20. echo "<script>alert(El email ingresado es inválido)</script>";
  21. echo "<script>location.href=javascript:history.back ()</script>";
  22. exit;//acá verifico que el email sea VALIDO, que tenga la forma [email protected]
  23. }
  24.  
  25. //**************** COMPRUEBO RADIO BOTON MARCADO **********************
  26. if (!($_POST['karate'])){
  27. echo "<script>alert(No deje email vacio)</script>";
  28. echo "<script>location.href=javascript:history.back ()</script>";
  29. exit;
  30. }
  31.  
  32. //**************** COMPRUEBO ciudad **********************
  33. if (!($_POST['ciudad'])){
  34. echo "<script>alert(No deje ciudad vacio)</script>";
  35. echo "<script>location.href=javascript:history.back ()</script>";
  36. exit;
  37. }
  38.  
  39. //**************** COMPRUEBO comentarios MARCADO **********************
  40. if (!($_POST['comentarios'])){
  41. echo "<script>alert(No deje email vacio)</script>";
  42. echo "<script>location.href=javascript:history.back ()</script>";
  43. exit;
  44. }
  45.  
  46. //**************** COMPRUEBO si aceptó las condiciones **********************
  47. if (!($_POST['A'])){
  48. echo "<script>alert(Debe aceptar las condiciones)</script>";
  49. echo "<script>location.href=javascript:history.back ()</script>";
  50. exit;
  51. }
  52.  
  53. //una vez que verifique todo, pues envÃ*o el email.
  54. //Declaras hacia donde se envÃ*a el correo, el Destinatario
  55. $recipiente = "[email protected]";
  56.  
  57. //defines el Asunto del correo
  58. $asunto = "Contacto desde la Pagina WEB ";
  59.  
  60. //defines el cuerpo del mensaje
  61. $message ="nombre: ".$_POST['nombre']."<br>";
  62. $message .="email: ".$_POST['email']."<br>";
  63. $message .="preferencias: ".$_POST['karate']."<br>";
  64. $message .="ciudad: ".$_POST['ciudad']."<br>";
  65. $message .="comentarios: ".$_POST['comentarios']."<br>";
  66.  
  67. $message = stripslashes($message);
  68.  
  69. //haces los encabezados
  70. $headers = "MIME-Version: 1.0\r\n";
  71. $headers .= "Content-type:text/html; charset=iso-8859-1\r\n";
  72. $headers .= "From: $email\r\n";
  73. $headers .= "Repaly-to: $email\r\n";
  74. $headers .= "Cc: ".$_POST['email']."\r\n";//le envÃ*as una copia al remitente
  75.  
  76. //chao email!!
  77. mail($recipiente,$asunto,$message,$headers);
  78.  
  79. echo "El mensaje se envió correctamente";
  80. ?>

Última edición por manupalaya; 03/10/2009 a las 15:24