You are here: Form Validation « PHP Programming Language « IT news, forums, messages
Form Validation

Posted by Jerim79 on 04/06/07 18:16

Here is my form:

<?php
$Number;
$Email;
$error=0;

if (empty($Number)){
$msg1="* You did not enter the number of people in your
household.";
$error++;
}

if (empty($Email)){
$msg2="* You did not enter your email address.";
$error++;
}

if ($error>0){
echo "<form action=\"{$_SERVER['PHP_SELF']}\" method=\"POST\">
<table width=\"700\" border=\"0\" cellpadding=\"0\" align=\"center\">
<tr>
<td colspan=\"34\"><div align=\"center\"><strong>SURVEY
</strong></div></td>
</tr>
<tr>
<td colspan=\"34\" bordercolor=\"#ECE9D8\" height=\"5\" align=\"center
\" > <hr/> <br/> <
</td>
</tr>
<tr>
<td colspan=\"34\">How many people are in your household?
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<input type=\"text\" name=\"Number\" width=\"40\" />$msg1</td>
</tr>
<tr>
<td colspan=\"34\" align=\"center\"><br/></td></tr>
<tr>
<td align=\"right\" colspan=\"15\">Please Enter Your Email
Address:&nbsp;</td>"
<td width=\"480\" colspan=\"24\"><input type=\"text\" name=\"Email\"
value=\"\" width=\"200\">$msg2</td>
</tr>
<tr>
<td colspan=\"34\">&nbsp;</td>
</tr>
<tr>
<td colspan=\"34\" align=\"center\"><input name=\"Submit\" type=
\"SUBMIT\" value=\"Continue\"/></td>
</tr>
</table>
</form>";
}

else {
include('nextpage.php');
}
?>

This works fine in that it catches what it needs to catch. However,
obviously, it prints out the error message upon first loading the
page. I would like to wait until after the user has clicked Submit and
the form has been posted, before it prints the error message to the
screen. Or is there a better way to do this? (I have done the separate
form for verification method before. I am trying to see if there is a
way to verify the form from within itself.)

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация