hi, im making a simple form where the user enter some info name,town,age,etc and takes this info to another php page where validates and send the info to my email. is if the user enter lets say some incorrect data the user will see a page with telling that an error ocurred and has to return back to correct that. my question is if i want to maintain what the user wrote when he returns to correct it how can i do that? does i have to use sessions? i will apreciate some help here thanks
Announcement
Collapse
No announcement yet.
form variables question
Collapse
X
-
you can protect against empty entry by protecting your mail() statement with and if(empty($_POST['element'])){ echo 'error'; }
-
Best error checking is done via regex, which I am no good at but mordred is mr regex.
To fill in the form fields, just have the form action to go against itself, ie
PHP Code:<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
PHP Code:<input name="email" value="<?php echo $_POST['email']; ?>"> Email
Comment
-
i try it but does not work the info desapears when the page called itself. but if i have 2 pages one that is the form where the user enter his/her info and another where validates the data entered and send the mail, how can i maintain the data entered in the first page when the second page needs to send back the user to complete or fix the info that was entered? i want that just to avoid that the user has to enter all the information again.
but thanks for the help.
Comment
-
ok, lets say this is the first page that appears. here the user fills this form to send me a message to my hotmail.
PHP Code:<?php
include("funciones.php");
conectar();
echo"<title>Enviame un mensaje</title>";
echo"<form action=checkmail.php method=post>";
echo"<table width=400 border=1 align=center cellpadding=5 cellspacing=0 >";
echo"<tr>";
echo"<th colspan=2>Mensaje para mi [[email protected]]</th>";
echo"</tr>";
echo"<tr>";
echo"<td>Nombre:</td>";
echo"<td><input type=text name=nombre size=30 maxlength=30></td>";
echo"</tr>";
echo"<tr>";
echo"<td>Pueblo:</td>";
echo"<td><input type=text name=pueblo size=30></td>";
echo"</tr>";
echo"<tr>";
echo"<td>Mensaje:<br>(no mayor de 200 caracteres)</td>";
echo"<td><textarea name=mensaje cols=30 rows=8></textarea></td>";
echo"</tr>";
echo"<tr>";
echo"<td>E-mail:</td>";
echo"<td><input type=text name=email size=30 maxlength=30 value=$email></td>";
echo"</tr>";
echo"<tr>";
echo"<td>Fecha de nacimiento:</td>";
echo"<td>";
echo"<select name=mes>";
echo"<option selected value=Enero>Enero";
echo"<option value=Febrero>Febrero";
echo"<option value=Marzo>Marzo";
echo"<option value=Abril>Abril";
echo"<option value=Mayo>Mayo";
echo"<option value=Junio>Junio";
echo"<option value=Julio>Julio";
echo"<option value=Agosto>Agosto";
echo"<option value=Septiembre>Septiembre";
echo"<option value=Octubre>Octubre";
echo"<option value=Noviembre>Noviembre";
echo"<option value=Diciembre>Diciembre</option></option></option></option></option></option></option></option></option></option></option></option>";
echo"</select>";
echo"<select name=dia>";
echo"<option selected value=1>01";
echo"<option value=2>02";
echo"<option value=3>03";
echo"<option value=4>04";
echo"<option value=5>05";
echo"<option value=6>06";
echo"<option value=7>07";
echo"<option value=8>08";
echo"<option value=9>09";
echo"<option value=10>10";
echo"<option value=11>11";
echo"<option value=12>12";
echo"<option value=13>13";
echo"<option value=14>14";
echo"<option value=15>15";
echo"<option value=16>16";
echo"<option value=17>17";
echo"<option value=18>18";
echo"<option value=19>19";
echo"<option value=20>20";
echo"<option value=21>21";
echo"<option value=22>22";
echo"<option value=23>23";
echo"<option value=24>24";
echo"<option value=25>25";
echo"<option value=26>26";
echo"<option value=27>27";
echo"<option value=28>28";
echo"<option value=29>29";
echo"<option value=30>30";
echo"<option value=31>31</option></option></option></option></option></option></option></option></option></option></option></option></option></option></option></option></option></option></option></option></option></option></option></option></option> </option></option></option></option></option>";
echo"</select>";
echo"<input maxlength=4 name=ano size=4>(yyyy)</td>";
echo"</td>";
echo"</tr>";
echo"<tr>";
echo"<td>Edad:</td>";
echo"<td><input type=text name=edad size=2 maxlength=2></td>";
echo"</tr>";
echo"<tr>";
echo"<td colspan=2 align=center><input type=submit name=submit value=Enviar></td>";
echo"</tr>";
echo"</table>";
echo"</form>";
?>
PHP Code:
<?php
include("funciones.php");
conectar();
$nombre = $_POST["nombre"];
$pueblo = $_POST["pueblo"];
$mes = $_POST["mes"];
$dia = $_POST["dia"];
$ano = $_POST["ano"];
$email = $_POST["email"];
$mensaje = $_POST["mensaje"];
$edad = $_POST["edad"];
if (empty($nombre))
{
die("Por favor entre su nombre. <a href=mail.php>Regresar</a>");
}
else if (empty($pueblo))
{
die("Por favor entre su pueblo. <a href=mail.php>Regresar</a>");
}
else if (empty($mensaje))
{
die("Por favor deje un mensaje. <a href=mail.php>Regresar</a>");
}
else if (strlen($mensaje) >200)
{
die("Mensaje muy largo (no mas de 200 caracteres). <a href=mail.php>Regresar</a>");
}
else if (empty($email))
{
die("Email en blanco. <a href=mail.php>Regresar</a>");
}
else if (ereg("([`~!#$%^&*-+=(){};,:?/\|])",$email))
{
die("Email con caractere/s incorrectos. <a href=mail.php>Regresar</a>");
}
else if (!ereg("@",$email))
{
die("Falta el caracter '@' en su e mail. <a href=mail.php>Regresar</a>");
}
else if (!ereg(".",$email))
{
die("Falta el caracter '.' en su e mail. <a href=mail.php>Regresar</a>");
}
else if (empty($ano))
{
die("Por favor entre su año de nacimiento. <a href=mail.php>Regresar</a>");
}
else if (empty($edad))
{
die("Por favor entre su edad. <a href=mail.php>Regresar</a>");
}
$info= "Info de la persona: $nombre,$pueblo,$dia.$mes.$ano, $edad, $email";
$mailto = "[email protected]";
$mailsubject = "Mensaje de $nombre";
$mailbody = $mensaje;
$result = mail($mailto,$mailsubject,$mailbody,$info);
if($result)
{
echo"<p><h4>El email fue enviado al administrador.</h4></p>";
echo"<a href=main.php>Pagina Principal</a>";
}
else
{
echo"<p>El email no se pudo enviar</p>";
}
?>
if i want to preserve the data that the user entered before an error ocurred how do i do that?
for ex. let say that the user enter his name,town,month,day,year and when the user entered the email forgot to put the @ character and continued to enter the info.
when the user clicks submit he will receive an error telling him that the @ character is missing and has to go back to correct that. right now the user has to enter all his info again.
i want to avoid that. i want that when the user returns has the info that he entered before, in this case just enter the @ character in the email and re submit the info. thats all.
thanks for the help anyway.Last edited by Programmer-PR; Feb 20, 2004, 11:55 PM.
Comment
Comment