|
Posted by Jerim79 on 04/05/07 18:33
I have been playing around with form validation. Here is what I have:
<?php
$Number=$_POST['Number'];
$Email=$_POST['Email'];
$error=0;
if (empty($Email)){
$msg2="* You did not enter your email address.";
$error++;
}
if ($error>0){
echo "<form action=\"{$_SERVER['PHP_SELF']}\" method=\"POST\">";
echo "<table width=\"700\" border=\"0\" cellpadding=\"0\" align=
\"center\">";
echo "<tr>";
echo "<td colspan=\"34\"><div align=\"center\"><strong>EDUCATIONAL
SEMINAR SURVEY </strong></div></td>";
echo "</tr>";
echo "<tr>";
echo "<td colspan=\"34\" bordercolor=\"#ECE9D8\" height=\"5\" align=
\"center\" > <hr/> <br/> </td>";
echo "</tr>";
echo "<tr>";
echo "<td colspan=\"34\">Before you begin the survey, could you
please tell us how many seminars you have attened during the Atlantic
City 2006 and the Las Vegas 2007 shows?
";
echo "<input type=\"text\" name=\"Number\" width=\"40\" />$msg1</
td>";
echo "</tr>";
echo "<tr>";
echo "<td colspan=\"34\" align=\"center\"><br/></td></tr>";
echo "<tr>";
echo "<td align=\"right\" colspan=\"15\">Please Enter Your Email
Address: </td>";
echo "<td width=\"480\" colspan=\"24\"><input type=\"text\" name=
\"Email\" value=\"\" width=\"200\">$msg2</td>";
echo "</tr>";
echo "<tr>";
echo "<td colspan=\"34\"> </td>";
echo "</tr>";
echo "<tr>";
echo "<td colspan=\"34\" align=\"center\"><input name=\"Submit\" type=
\"SUBMIT\" value=\"Continue\"/></td>";
echo "</tr>";
echo "</table>";
echo "</form>";
}
else {
include('survey.php');
}
?>
So it does some data validation at the top. If $Email is empty, it
shows the form on the screen for the user to fill out. It also puts
the appropriate error message next to the email question. If $Email is
not empty when the user clicks submit, the form verifies it is not
empty, and then calls the next page. The obvious problem is that when
the page first loads, it displays the error message.
Navigation:
[Reply to this message]
|