Forum Moderators: coopster
Presently, my code finds the first error on validation and then displays it. Once the error been corrected by the user, the validation routine displays the next error upon resubmission and displays that error. This routine is very time consuming and i would like to see all errors displayed at once for the user to see and correct.
your help would be very appreciative.
thanks
larrym
here is the php code of the form page:
<?php
session_start();
if(isset($_SESSION['error']))
echo $_SESSION['error'];
?>
here is the session part of the server side script:
session_start();
$_SESSION['from'] = $from;
if (strlen($from) <2)
{header("Location: contact-us.php?status=0");
$_SESSION['error'] = 'Please enter your name';
exit;}
$_SESSION['email'] = $email;
if (!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email))
{header("Location: contact-us.php?status=0");
$_SESSION['error'] = 'Please enter your your correct email';
exit;}
$_SESSION['telnr'] = $telnr;
if( (strlen($telnr)<7) Or (strlen($telnr)>14) )
{header("Location: contact-us.php?status=0");
$_SESSION['error'] = 'Please enter your correct phone number';
exit;}
$_SESSION['street'] = $street;
if (strlen($street) <3)
{header("Location: contact-us.php?status=0");
$_SESSION['error'] = 'Please enter your street';
exit;}
$_SESSION['city'] = $city;
if (strlen($city) <2)
{header("Location: contact-us.php?status=0");
$_SESSION['error'] = 'Please enter a valid city';
exit;}
$_SESSION['state'] = $state;
if (strlen($state) == 0 )
{header("Location: contact-us.php?status=0");
$_SESSION['error'] = 'Please choose a valid state';
exit;}
$_SESSION['zipcode'] = $zipcode;
if( (strlen($zipcode)<5) Or (strlen($zipcode)>10) )
{header("Location: contact-us.php?status=0");
$_SESSION['error'] = 'Please enter a valid zipcode';
exit;}
$_SESSION['subject'] = $subject;
if (strlen($subject) == 0 )
{header("Location: contact-us.php?status=0");
$_SESSION['error'] = 'Please choose a valid subject';
exit;}
if ($_POST['captcha'] != $_SESSION['captchacode'])
{header("Location: contact-us.php?status=2");
$_SESSION['error'] = 'You did not enter the letters shown in the image for validation';
captchaDone();
exit;}
$error = '';
if (strlen($from) <2)
{
$error .= 'Please enter your name<br />';
}
if( (strlen($telnr)<7) Or (strlen($telnr)>14) )
{
$error .= 'Please enter your correct phone number<br />';
}
// etc.
if($error)
{
$_SESSION['error'] = $error;
header("Location: contact-us.php?status=0");
die;
}