I am working on an html order form that has some Javascript validation, and uses PHP to send the order by email to the administrator, with a copy to the purchaser. I also am ‘trying’ to use PHP to validate the form. I have almost no experience in PHP, and some experience in Javascript coding.
As a result, most of the PHP code I am using I have borrowed and adapted from elsewhere, but I do understand what it is doing and was able to add some of my own successfully.
My problem is getting the error messages to show up instead of $error. I have included the relevant code (the middle part is part of the form processing so I left it out because it works like a charm). The only thing that doesn’t seem to be responding is the last statement echo $error;
I am too inexperienced to be able to figure out what I have done wrong here, so I was wondering if someone could help. Please be patient if it was a stupid mistake that I couldn’t see.
$errors = '';
if (empty($_POST['fullname']) ||
empty($_POST['campername']) ||
empty($_POST['phone']) ||
empty($_POST['email']))
{
$errors .= "\
Error: all fields are required";
}
$fullname = $_POST['fullname'];
$campername = $_POST['campername'];
$phone = $_POST['phone'];
$email = $_POST['email'];
if (!eregi(
"^[_a-z0-9-]+(\\.[_a-z0-9-]+)*@[a-z0-9-]+(\\.[a-z0-9-]+)*(\\.[a-z]{2,3})$",
$email))
{
$errors .= "\
Error: Invalid email address";
}
.
.
.
.
.
.
.
if( empty($errors))
{
//redirect to the 'thank you' page
header('Location: thankyou.html');
// Email message sent to administrator with a copy to the purchaser
$message = <<<EOD
<br/><hr/><br/>
Name: $fullname <br/>
Camper's Name: $campername <br/>
Phone Number: $phone <br/>
Email Address: $email <br/>
<p>The following items were ordered:<br/>
$purchase<br/><br/>
Total Payment Due: $totalAmt</p>
Comments: $comments<br /><br />
$fullname will $payment the payment<br/>
and pick up the order at $pickup date.<br/>
EOD;
$headers = "From: $email\\r\
";
$headers .= "Content-type: text/html\\r\
";
$headers .= "Cc: $email \\r\
";
mail($webMaster, $emailSubject, $message, $headers);
}
echo $errors;