Ver Mensaje Individual
  #7 (permalink)  
Antiguo 10/02/2010, 07:39
margancia
 
Fecha de Ingreso: febrero-2009
Mensajes: 193
Antigüedad: 15 años, 2 meses
Puntos: 3
Respuesta: Agregar input radio a un formulario y que funcione envío

Muchas gracias por tu respuesta Dany_s, probé lo que me dijiste y logré hacerlo andar, pero un par de veces no llegó el email, hice bien el código o tuve algún error?

También si no se hace click en ninguno de los dos input radio se envia igual y no hay ningun tipo de validacion...

HTML:
Código HTML:
<div id="contact_form">
  <form name="contact" method="post" action="">
    <fieldset>
      <label for="name" id="name_label">Name</label>
      <input type="text" name="name" id="name" size="30" value="" class="text-input" />
      <label class="error" for="name" id="name_error">This field is required.</label>
      
      <label for="emaildestinatario" id="emaildestinatario_label">Return Email</label>
          <input type="radio" name="emaildestinatario" value="[email protected]" />
    <input type="radio" name="emaildestinatario" value="[email protected]" />
      <label class="error" for="emaildestinatario" id="emaildestinatario_error">This field is required.</label>
      
      <label for="phone" id="phone_label">Return Phone</label>
      <input type="text" name="phone" id="phone" size="30" value="" class="text-input" />
      <label class="error" for="phone" id="phone_error">This field is required.</label>
      
    	<br />
      <input type="submit" name="submit" class="button" id="submit_btn" value="Send" />
    </fieldset>
  </form>
</div> 

TUTORIAL.JS:
Código:
$(function() {
  $('.error').hide();
  $('input.text-input').css({backgroundColor:"#FFFFFF"});
  $('input.text-input').focus(function(){
    $(this).css({backgroundColor:"#FFDDAA"});
  });
  $('input.text-input').blur(function(){
    $(this).css({backgroundColor:"#FFFFFF"});
  });

  $(".button").click(function() {
		// validate and process form
		// first hide any error messages
    $('.error').hide();
		
	  var name = $("input#name").val();
		if (name == "") {
      $("label#name_error").show();
      $("input#name").focus();
      return false;
    }
var emaildestinatario = $('input[name=emaildestinatario]:checked').val();
		if (emaildestinatario == "") {
      $("label#emaildestinatario_error").show();
      return false;
    }
		var phone = $("input#phone").val();
		if (phone == "") {
      $("label#phone_error").show();
      $("input#phone").focus();
      return false;
    }
		
		var dataString = 'name='+ name + '&email=' + email + '&phone=' + phone + '&emaildestinatario=' + emaildestinatario;
		//alert (dataString);return false;
		
		$.ajax({
      type: "POST",
      url: "bin/process.php",
      data: dataString,
      success: function() {
        $('#contact_form').html("<div id='message'></div>");
        $('#message').html("<h2>Contact Form Submitted!</h2>")
        .append("<p>We will be in touch soon.</p>")
        .hide()
        .fadeIn(1500, function() {
          $('#message').append("<img id='checkmark' src='images/check.png' />");
        });
      }
     });
    return false;
	});
});
runOnLoad(function(){
  $("input#name").select().focus();
});

PROCESS.PHP
Código:
<?php
if ((isset($_POST['name'])) && (strlen(trim($_POST['name'])) > 0)) {
	$name = stripslashes(strip_tags($_POST['name']));
} else {$name = 'No name entered';}
if ((isset($_POST['emailemaildestinatario'])) && (strlen(trim($_POST['emailemaildestinatario'])) > 0)) {
	$emailemaildestinatario = stripslashes(strip_tags($_POST['emailemaildestinatario']));
} else {$emailemaildestinatario = 'No emaildestinatario entered';}
if ((isset($_POST['phone'])) && (strlen(trim($_POST['phone'])) > 0)) {
	$phone = stripslashes(strip_tags($_POST['phone']));
} else {$phone = 'No phone entered';}
ob_start();
?>
<html>
<head>
<style type="text/css">
</style>
</head>
<body>
<table width="550" border="1" cellspacing="2" cellpadding="2">
  <tr bgcolor="#eeffee">
    <td>Name</td>
    <td><?=$name;?></td>
  </tr>
  <tr bgcolor="#eeeeff">
    <td>Email</td>
    <td><?=$email;?></td>
  </tr>
  <tr bgcolor="#eeffee">
    <td>Phone</td>
    <td><?=$phone;?></td>
  </tr>
</table>
</body>
</html>
<?
$body = ob_get_contents();

$to = '$emaildestinatario';
$email = '$emaildestinatario';
$fromaddress = "[email protected]";
$fromname = "Online Contact";

require("phpmailer.php");

$mail = new PHPMailer();

$mail->From     = "[email protected]";
$mail->FromName = "Contact Form";
$mail->AddAddress("$emaildestinatario","Name 1");
$mail->AddAddress("$emaildestinatario","Name 2");

$mail->WordWrap = 50;
$mail->IsHTML(true);

$mail->Subject  =  "Demo Form:  Contact form submitted";
$mail->Body     =  $body;
$mail->AltBody  =  "This is the text-only body";

if(!$mail->Send()) {
	$recipient = '$emaildestinatario';
	$subject = 'Contact form failed';
	$content = $body;	
  mail($recipient, $subject, $content, "From: $emaildestinatario\r\nReply-To: $email\r\nX-Mailer: DT_formmail");
  exit;
}
?>

Muchas gracias por todo a todos!
Saludos,
Margancia