Thank you halojoy,
I took out the else statement again which gets rid of the parse error, but like before this opens up a whole new can of worms leaving this messages....
Notice: Undefined variable: blank_array in /Applications/MAMP/htdocs/lesson4/form4.inc on line 65
Warning: Invalid argument supplied for foreach() in /Applications/MAMP/htdocs/lesson4/form4.inc on line 65
Notice: Undefined variable: error_array in /Applications/MAMP/htdocs/lesson4/form4.inc on line 136
Warning: Invalid argument supplied for foreach() in /Applications/MAMP/htdocs/lesson4/form4.inc on line 136
I can't figure out what the problem is, in the code I'm to identify when the validation errors occur in the form...but I think I did define everything. Sorry for all the trouble but I've been stumped on this very problem for days now.
Here is the updated code getting rid of the else statement...
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>form4.inc</title>
<style type='text/css'>
<!--
form {
margin: 1.5em 0 0 0;
padding: 0;
}
#field {padding-bottom: 1em;}
label {
font-weight: bold;
float: left;
width: 20%;
margin-right: 1em;
text-align: right;
}
#submit {
margin-left: 35%;
}
-->
</style>
</head>
<body>
<?php
/* Program use: VALIDATE
* Description: Program checks all the form fields for
* invalide content
*/
foreach($_POST as $field => $value)
{
if(empty($value))
{
$blank_array[] = $field;
}
else
{
$good_data[$field] = strip_tags(trim($value));
}
if(@sizeof($blank_array) > 0)
{
$message = "<p style='color: red; margin-bottom: 0;font-weight: bold'>
You didn't fill in one or more required fields.
You must enter:
<ul style='color: red; margin-top: 0;
list-style: none' >";
}
}
foreach($blank_array as $value)
{
{
$message .= "<li>$value</li>";
}
{
$message .= "</ul>";
echo $message;
}
{
extract($good_data);
include("form4.inc");
exit();
}
}
foreach($_POST as $field => $value)
{
if(!empty($value))
{
$last_name = "/^[A-Za-z' -]{1,50}$/";
$first_name = "/^[A-Za-z' -]{1,50}$/";
$email = "\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b}";
$phone = "/^[0-9)(xX -]{7,20}$/";
$order_date ="(19|20)\d\d[- /.](0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])";
$address = "^[0-9)( A-Za-z-]{7,20}";
$city ="[A-Za-z ] {50}";
$state = "/A-Za-z {2}/";
$radio = "/(male|female)/";
}
if(!preg_match($last_name,$value))
{
$error_array[] = "$value is not a valid name";
}
if(!preg_match($first_name,$value))
{
$error_array[] = "$value is not a valid name";
}
if(!preg_match($email,$value))
{
$error_array[] = "$value is not a valid email";
}
if(preg_match($phone,$value))
{
$error_array[] = "$value is not a valid phone number";
}
if(!preg_match($radio,$value))
{
$error_array[] = "$value is not a valid gender";
}
$clean_data[$field] = strip_tags(trim($value));
if(@sizeof($error_array) > 0)
{
$message = "<ul style='color: red; list-style: none' >";
}
}
foreach($error_array as $value)
{
{
$message .= "<li>$value</li>";
}
{
$message .= "</ul>";
}
{
echo $message;
extract($clean_data);
}
exit();
}
?>
<?php
$labels = array( "last_name" => "Last Name",
"first_name" => "First Name",
"email" => "Email",
"phone" => 'Phone',
'order_date' => "Order Date",
"address" => "Address",
"city" => "City",
"state" => "State");
$radios = array( "male"=> "Male",
"female"=> "Female");
?>
</body>
</html>