Código HTML:
<table width="100%" border="0" cellspacing="4" cellpadding="0"> <form name="myform"> <!-- method="post" action="contar.php" --> <tr> <td>Nombre:</td> <td> <input type="text" id="namefield" name="namefield" size="30"></td> </tr> <tr> <td>Email:</td> <td> <input id="emailfield" type="text" name="emailfield" size="30" /></td> </tr> <tr> <td>Telefono:</td> <td> <input type="text" name="telfield" id="telfield" size="30"></td> </tr> <tr> <td>Comentario:</td> <td> <textarea id="comments" name="comments" rows="5" cols="26" ></textarea></td> </tr> <tr><td colspan="2" align="center"><input type="reset" value="Restablecer" name="B2"> <input type="submit" value="Enviar" name="B1"onClick="parent.emailwindow.hide()" > </td></tr> </form> </table>
Código HTML:
<script type="text/javascript"> function emailform(){ emailwindow=dhtmlmodal.open('EmailBox', 'iframe', 'modalfiles/emailform.html', 'Contact email form page', 'width=370px,height=450px,center=1,resize=0,scrolling=0') emailwindow.onclose=function(){ var theform=this.contentDoc.forms[0] var theemail=this.contentDoc.getElementById("emailfield") var thename=this.contentDoc.getElementById("namefield") var thecomments=this.contentDoc.getElementById("comments") var emailfilter=/^\w+[\+\.\w-]*@([\w-]+\.)*\w+[\w-]*\.([a-z]{2,4}|\d+)$/i var returnval=emailfilter.test(theemail.value) if (thename.value.length==0){ alert("Por favor escribe tu nombre") thename.select() return false } else if (returnval==false){ alert("E-mail invalido") theemail.select() return false } else if (thecomments.value.length==0){ alert("Deja tu comentario") thecomments.select() return false } else{ // this is a valid email document.getElementById("youremail").innerHTML='Gracias '+thename.value+', pronto estaremos en contacto en '+theemail.value return true; // allow closing of window } } } </script>
Código PHP:
if (isset($_POST['submit'])) {
// We get all the variables
foreach ($_POST as $key=>$value) {
if ( gettype( $value ) == "array" ) {
//print "$key == <br>\n";
} else {
//print "$key == $value<br>\n";
$key = $value;
}
}
$message = "FORMULARIO DE CONTACTO\n" .
"\nNombre: " . $nombre .
"\nEmail: " . $mail .
"\ndireccion: " . $direccion .
$to = 'alguien@my_mail.com';
$subject = 'Formulario de contacto';
$headers = "From: Somebody\r\n";
mail($to,$subject,$message,$headers);
header('Location: gracias.htm'); // Esta linea redirije a otra pagina...la podes sacar
} else {
echo 'ERROR! de acceso.';
}
Desde el js, cuando return = true: Que sigue? como lo mando?