
Originally Posted by
kuau
Yes, a php script, but it comes into play only after the form is submitted. I don't know how to do a pop-up window in php so would have to send them to an error page and by then the person would have gone away. Is there an easy way to do the php check? If not, can't I just improve that javascript? What do other people do? Thanks, erin
submit it to a validation function and in the validation function you check for each required field. if that field contains an error you place the a message containing the field into an error array.
at the very end of the validation function after you have done all of your checks on individual fields you do one last check to see if the error array has been populated. if there are values in the error array you send the user back to the form notifying them of the errors (typically its done in a list in red / outstanding color)
This creates some extra work but you shouldn't force the user to re-enter every single value again, but rather save each of the form fields and populate all of the ones that are correct with the previous values to prevent duplication, and call attention to the fields that are in error (typically with a different background color)
That last bit about auto-populating the old values will create less frustration for the user, but it's only to help keep the user from being frustrated and leaving your page...
that may have been hard to understand so here is some psuedo code
Code:
<?php
function process_form()
{
$error = array();
if(field required)
{
condition
if( bad_condition )
{
$error[] = "Message about required field";
}
}
...
if(isset($error))
{
display_form($errors);
}
}
function display_form($error)
{
if($error)
{
echo "<ul>";
foreach($error as $err)
{
echo "\n\t<li>". $err ."</li>";
}
echo "</ul>";
?>
--- REST OF FORM INFORMATION HERE ---
<?php
}
}
if(submitted)
{
process_form();
}
else
{
display_form();
}
Bookmarks