jbdesign
New Member
- Messages
- 26
- Reaction score
- 0
- Points
- 0
EDIT:I just figured out what my problem was... god I feel so stupid sometimes. Please feel free to delete this thread.
On the form I am making I am trying to require the visitor to select a yes or no radio button, before the information is submitted. Problem is the regex validation isn't working, they can submit without selecting either one. Here is the code:
I stripped out some of the other code that doesn't pertain to my problem.
On the form I am making I am trying to require the visitor to select a yes or no radio button, before the information is submitted. Problem is the regex validation isn't working, they can submit without selecting either one. Here is the code:
Code:
<?php
if(isset($_POST['submitted']) and $_POST['submitted'] == "yes")
{
foreach($_POST as $field => $value)
{
if(empty($value))
{
if($field != "middle_name")
{
$blank_array[] = $field;
}
}
else
{
$good_data[$field] = strip_tags(trim($value));
}
}
if(@sizeof($blank_array) > 0)
{
/*Display error message if information is not entered*/
$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("lesson4_form.inc");
exit();
}
foreach($_POST as $field => $value)
{
if(!empty($value))
{
$name_patt = "/^[A-Za-z' -]{1,50}$/";
$radio_patt = "/(yes|no)/i";
if(preg_match("/name/i",$field))
{
if(!preg_match($name_patt,$value))
{
$error_array[] = "$value is not a valid name";
} //end of name check
}
if(preg_match("/status/i",$field))
{
if(!preg_match($radio_patt,$value))
{
$error_array[] = "$value is not a valid status";
} //end of radio button check
}
}
$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);
include("information_form.inc");
exit();
}
else
{
echo "Data is all okay";
};
}
else
{
include("information_form.inc");
}
?>
I stripped out some of the other code that doesn't pertain to my problem.
Last edited: