Ver Mensaje Individual
  #4 (permalink)  
Antiguo 02/05/2013, 14:30
dudamk
 
Fecha de Ingreso: mayo-2013
Mensajes: 36
Antigüedad: 11 años, 9 meses
Puntos: 0
Respuesta: Medición de envíos

Gracias! Os copio todo:

index.html

Código HTML:
Ver original
  1. <form id="register-form" method="post" onSubmit="_gaq.push(['_trackEvent', 'Landing', 'Submit']);" >
  2.       <input type="text" name="email" placeholder="Tu email" />
  3.       <input type="text" name="name" placeholder="Tu nombre" />
  4.       <input type="text" name="phone" placeholder="Número de teléfono" />
  5.       <input type="submit" name="submit" value="Quiero saber más sobre esta oferta" class="btn" />
  6.      </form>


register.php

Código PHP:
Ver original
  1. <?php
  2. if(isset($_POST['action'])) { // Checking for submit form
  3. $my_emails  = array("[email protected]", "[email protected]", "[email protected]"); // Your email address
  4. if($_POST['action']=='add') {
  5. $email   = trim(strip_tags(addslashes($_POST['email'])));
  6. $name    = trim(strip_tags(addslashes($_POST['name'])));
  7. $phone   = trim(strip_tags(addslashes($_POST['phone'])));
  8. $pattern    = '/^[^\W][a-zA-Z0-9_]+(\.[a-zA-Z0-9_]+)*\@[a-zA-Z0-9_]+(\.[a-zA-Z0-9_]+)*\.[a-zA-Z]{2,4}$/';
  9. if($phone==""){
  10. echo "error|Por favor, introduce tu número de teléfono";
  11. }
  12. if($email != "" && $name != "" && $name != "") {
  13. if(preg_match($pattern, $email)) {
  14. $messages   = "Has recibido una solicitud de información de: " . $name . "\r\n" . "Puedes responder directamente a este email o llamarle al siguiente número de teléfono: " . $phone;
  15. $headers = "From: " . $email . "\r\n";
  16. foreach($my_emails as $my_email) mail($my_email, $subject, $messages, $headers);
  17. echo "success| ¡Muchas gracias! En breve nos pondremos en contacto contigo";
  18. } else {
  19. echo "eerror|Por favor, introduce una dirección de email válida";  
  20. }
  21. } else {
  22. echo "error| Por favor, rellena todos los campos"; 
  23. }
  24. }
  25. } else { // Submit form false
  26. header("Location: index.html");
  27. }
  28. ?>


main.js

Código Javascript:
Ver original
  1. // Register form process function
  2.     $("#register-form").submit(function() {
  3.         var submitData  = $(this).serialize();
  4.         var $email      = $(this).find("input[name='email']");
  5.         var $name       = $(this).find("input[name='name']");
  6.         var $phone      = $(this).find("input[name='phone']");
  7.         var $submit     = $(this).find("input[name='submit']");
  8.         var output      = '';
  9.        
  10.         $email.attr('disabled','disabled');
  11.         $name.attr('disabled','disabled');
  12.         $phone.attr('disabled','disabled');
  13.         $submit.attr('disabled','disabled');
  14.        
  15.         $.ajax({ // Send an offer process with AJAX
  16.             type: "POST",
  17.             url: "register.php",
  18.             data: submitData + "&action=add",
  19.             dataType: "html",
  20.             success: function(msg){
  21.                
  22.                 if(parseInt(msg, 0) !== 0) {
  23.                     var msg_split = msg.split("|");
  24.                     if(msg_split[0] === "success") {
  25.                         $email.val('').removeAttr('disabled');
  26.                         $name.val('').removeAttr('disabled');
  27.                         $phone.val('').removeAttr('disabled');
  28.                         $submit.removeAttr('disabled');
  29.                         output  += '<div class="submit-status submit-status-success">' + msg_split[1] + '</div>';
  30.                         $("body").prepend(output).find(".submit-status").hide().slideDown().delay(4000).slideUp(function() { $(this).remove(); });
  31.                     } else {
  32.                         $email.removeAttr('disabled');
  33.                         $name.removeAttr('disabled');
  34.                         $phone.removeAttr('disabled');
  35.                         $submit.removeAttr('disabled');
  36.                         output  += '<div class="submit-status submit-status-error">' + msg_split[1] + '</div>';
  37.                         $("body").prepend(output).find(".submit-status").hide().slideDown().delay(4000).slideUp(function() { $(this).remove(); });
  38.                     }
  39.                 }
  40.             }
  41.         });
  42.         return false;
  43.     });