Cita:
Iniciado por esjuanma
Está faltando código.
Pensé que no hacía falta toda la ristra de código pero bueno, aquí la dejo:
Código HTML:
Ver original<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
Código Javascript
:
Ver original<script type="text/javascript">
function validar(formulario) {
var edad = 14;
if(formulario.subject.value.length == '' || formulario.name.value.length == "" || formulario.age.value.length == "" || formulario.address.value.length == "" || formulario.zipcode.value.length == "" || formulario.telephone.value.length == "" || formulario.ageover.value == "") {
alert("Error: \nFalta por rellenar algunos campos.");
return false;
}
if(isNaN(formulario.age.value)) {
alert("Error:\nEste campo debe tener sólo números.");
formulario.age.focus();
return false;
}
if(isNaN(formulario.zipcode.value) || formulario.zipcode.value.length < 5){
alert("Error: \nEl código postal es incorrecto.");
formulario.zipcode.focus();
return false;
}
if(isNaN(formulario.telephone.value) || formulario.telephone.value.length < 9){
alert("Error: \n El número de teléfono que has introducido está mal.");
formulario.telephone.focus();
return false;
}
if(formulario.age.value <= edad && formulario.ageover.value != 1){
alert('Error: \nEres menor de 14 años. Por favor, marca la casilla \"Si\" ');
return false;
}
if(formulario.ageover.value != 1){
document.getElementById('capaRadio').style.display='none';
}
return true;
}
function show(){
if(document.getElementById('capaRadio').style.display == 'none'){
document.getElementById('capaRadio').style.display='block';
document.getElementById('capaMayorEdadRadio').style.display='none';
}else{
document.getElementById('capaRadio').style.display='none';
}
}
function dontshow(){
if(document.getElementById('capaMayorEdadRadio').style.display == 'none'){
document.getElementById('capaMayorEdadRadio').style.display='block';
document.getElementById('capaRadio').style.display='none';
}else{
document.getElementById('capaMayorEdadRadio').style.display='none';
}
}
</script>
Código PHP:
<?php
$validation = $_REQUEST['validation'];
if(isset($validation) == 1){
$subject = $_REQUEST['subject'];
$name = $_REQUEST['name'];
$age = $_REQUEST['age'];
$address = $_REQUEST['address'];
$zipcode = $_REQUEST['zipcode'];
$telephone = $_REQUEST['telephone'];
$ageover = $_REQUEST['ageover'];
$readername = $_REQUEST['readername'];
$tutorname = $_REQUEST['tutorname'];
$tutoremail = $_REQUEST['tutoremail'];
$tutortelephone = $_REQUEST['tutortelephone'];
$tutorauth = $_REQUEST['tutorauth'];
if($ageover != 1){
if(isset($subject) == "" || isset($name) == "" || isset($age) == "" || isset($address) == "" || isset($zipcode) == "" || isset($telephone) == "" || isset($ageover) == "" || ($age <= 14 && $tutorauth != 1 ) ){
echo "Te has olvidado de rellenar algún campo. <a href='javascript:history.back(-1)'>Volver atrás</a>";
exit;
}else{
$from = "[email protected]";
$for = "hola@hola.
$header = "From: " . $from . " rn";
$header .= "X-Mailer: PHP/" . phpversion() . " rn";
$header .= "Mime-Version: 1.0 rn";
$header .= "Content-Type: text/html; charset=utf-8";
$content = "<h1>Formulario Como Tú</h1>";
$content .= "<b>Nombre: </b>".$name."<br>";
if(mail($for, $subject, $content, $header)){
echo "Te has suscrito al concurso satisfactoriamente. Gracias por participar.";
exit;
}else{
echo "Ha habido un problema al suscribirte al concurso. Inténtalo de nuevo pasados unos minutos";
}
}
}else{
if( ($age > 14 && $tutorauth == 1 ) || isset($readername) == "" || isset($tutorname) == "" || isset($tutoremail) == "" || isset($tutortelephone) == "" || isset($tutorauth) == "" ){
echo "Ha habido un error en un campo. Por favor, verifíquelo. <a href='javascript:history.back(-1)'>Volver atrás</a>";
exit;
}else{
if($tutorauth != 1){
echo "<div>Tienes que <strong>autorizar la participación del menor</strong> para poder participar.</div>";
exit;
}else{
if($tutorauth == 1){
$tutorauth = "Si";
}
$from = "aaa@eee.es";
$for = "aaa@aaa.com";
$header = "From: " . $from . " rn";
$header .= "X-Mailer: PHP/" . phpversion() . " rn";
$header .= "Mime-Version: 1.0 rn";
$header .= "Content-Type: text/html; charset=utf-8";
$content = "<h1>Formulario Como Tú</h1>";
$content .= "<b>Nombre: </b>".$name."<br>";
$content .= "<b>Nombre y Apellidos de la lectora: </b>".$readername."<br>";
$content .= "<b>Nombre y apellidos del padre / madre / tutor: </b>".$tutorname."<br>";
$content .= "<b>E-mail del padre / madre / tutor: </b>".$tutoremail."<br>";
$content .= "<b>Teléfono del padre / madre / tutor: </b>".$tutortelephone."<br>";
$content .= "<b>Autorizo la participación del menor a mi cargo: </b>".$tutorauth."<br>";
if(mail($for, $subject, $content, $header)){
echo "Te has suscrito al concurso satisfactoriamente. Gracias por participar.";
exit;
}else{
echo "Ha habido un problema al suscribirte al concurso. Inténtalo de nuevo pasados unos minutos";
}
}
}
}
}
?>
Código HTML:
Ver original<form action="#" method="post" name="envioFormulario" onSubmit = "return validar(this)"> <table width="600" border="1" align="center"> <th width="100%" colspan="2">Formulario
</th> <td width="50%"><div align="right">Asunto
</div></td> <input type="text" name="subject" id="textfield" /> <td><input type="text" name="name" id="textfield" /></td> <td><input type="text" name="age" id="textfield" maxlength="2" /></td> <td><input type="text" name="address" id="textfield" /></td> <td><input type="text" name="zipcode" id="textfield" maxlength="5"/></td> <td><input type="text" name="telephone" id="textfield" maxlength="9" /></td> <td><div align="right">¿Eres menor de 14 años?
</div></td> Si
<input type="radio" name="ageover" onclick="return show();" value="1"> No
<input type="radio" name="ageover" onclick="return dontshow();" value="0"/> <div id="capaMayorEdadRadio" style="display:none"> <p>Tus datos van a formar parte de un fichero del que es responsable
<div id="capaRadio" style="display:none;"> <table border="1" width="100%"> Autorización Paterna
<td align="right" width="50%">Nombre y apellidos de la lectora:
</td> <td><input type="text" name="readername" id="textfield" /></td> <td align="right">Nombre y apellidos del padre / madre / tutor:
</td> <td><input type="text" name="tutorname" id="textfield" /></td> <td align="right">E-mail del padre / madre / tutor:
</td> <td><input type="text" name="tutoremail" id="textfield" /></td> <td align="right">Teléfono del padre / madre / tutor:
</td> <td><input type="text" name="tutortelephone" id="textfield" maxlength="9" /></td> <td align="right">Autorizo la participación del menor a mi cargo
</td> <td><input name="tutorauth" type="checkbox" value="1" /></td> <p>Tus datos y que tiene como única finalidad gestionar las promociones o sorteos que organiza la web revistacomotu.com y la revista COMO TÚ, así como gestionar la entrega del premio que ganes.
</p>
<td colspan="2"> </td> <td><input name="validation" type="hidden" value="1" /></td> <td><input name="enviar" type="submit" value="Enviar" /></td>