This will be the first of two or three scripts that I will be writing to handle form validation. I know my syntax is correct because I am able to get past the PHP to load the HTML code which displays the form. In testing the form by submitting it blank and filling it out with correct information, I get a CGI error stating that output has started before headers were received. The script is below, along with the <HEAD> section of the HTML code.
<?php
//validate the form data submitted
//e-mail it if it all checks out ok
if (isset($HTTP_POST_VARS['Submit']))
{
$message[] = "The following errors occurred in processing the form<br>";
//check the name
if (eregi ("/^\S+\s+\S+$/", $HTTP_POST_VARS['T1']))
{
$nameok=TRUE;
}
else
{
$message[] = "Please enter your name, no numbers or special characters please<br>";
$nameok=FALSE;
}
//check organization name
if (strlen ($HTTP_POST_VARS['T2']) == 0)
{
$message[] = "Please enter your organization name<br>";
$orgok = FALSE;
}
else
{
$orgok = TRUE;
}
if (strlen ($HTTP_POST_VARS['T3']) == 0)
{
$message[] = "Please enter your address<br>";
$addressok = FALSE;
}
else
{
$addressok = TRUE;
}
if (strlen ($HTTP_POST_VARS['T4']) == 0)
{
$message[] = "Please enter your city<br>";
$validcity = FALSE;
}
else
{
$validcity = TRUE;
}
if (strlen ($HTTP_POST_VARS['T5']) != 2)
{
$message[] = "Please enter your state<br>";
$validstate = FALSE;
}
else
{
$validstate = TRUE;
}
if (eregi ("^[0-9]{5,5}(-[0-9]{4,4})?$", $HTTP_POST_VARS['T6']))
{
$zipok=TRUE;
}
else
{
$message[] = "Please enter your zip code. zip+4 is optional.<br>";
$zipok=FALSE;
}
if (eregi ("^(\()[0-9]{3,3}(\))(\-)[0-9]{3,3}\-[0-9]{4,4}$", $HTTP_POST_VARS['T7']))
{
$phoneok=TRUE;
}
else
{
$message[] = "Please enter your phone number with area code<br>";
$phoneok=FALSE;
}
$newcomments = strip_tags($HTTP_POST_VARS['S1']);
//check as a regular expression. Verify that a '@' exists, along with at least one '.'
if (eregi ("^([[:alnum:]]|_|\.|-)+@([[:alnum:]]|\.|-)+(\.)([a-z]{2,4})$", $HTTP_POST_VARS['T10']))
{
$validemail = TRUE;
}
else
{
$message[] = "Please enter a valid e-mail address.<br>";
$validemail = FALSE;
}
if ($nameok &&
$orgok &&
$addressok &&
$validcity &&
$validstate &&
$zipok &&
$phoneok &&
$validemail)
{
echo "it worked\n";
}
else
{
echo "<div align=\"left\"><font color=\"ff0000\"><b>";
foreach ($message as $key => $value)
{
echo "$value <br>\n";
}
}
}
?>
<html>
<head>
<meta http-equiv="Content-Language" content="en-us">
<meta name="GENERATOR" content="Microsoft FrontPage 5.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Event Quote Request</title>
<!-- Javascript for navbar omitted -->
</head>