Hello folks, I am brand new to the forum and very new to PHP so please be gentle.
I have created a simple form where I collect some basic information from the user and check that data. The script checks for blanks and proper formatting in the fields with regular expressions. The good information is stored in two arrays called $clean_data[] and $good_data[]. If not all required fields are filled in the form is re-displayed but not before using the extraxt function and passing it the $clean_data and $good_data[] arrays so that the user does not need to fill in all fields again. This works to a degree, but I am not sure how to have the radio button the user selected re-checked when the form is re-displayed. I am doing a check on the radio button vs. a regular expression where only 4 options are available and if the data is good it is stored in $good_data, I assumed. If anyone happens to have a moment to smack me upside the head and tell me what I am doing wrong it would be greatly appreciated.
Here is my form:
<?php /* Program name: my-form.inc * Description: Defines a form that collects a user's * information. */ $labels = array( "first_name" => "First Name", "middle_name" => "Middle Name", "last_name" => "Last Name", "phone" => "Phone", "street" => "Street Address", "postal" => "Postal Code" ); $radios = array( "NS", "PEI", "NB", "NFLD" ); $submit = "Submit Information"; ?> <!-- form { margin: 1.5em 0 0 0; border : 1px solid #000; padding : 5px; background-color : #fff; }
.field {padding-bottom: 1em;}
label {
font-weight: bold;
float: left;
width: 20%;
margin-right: 1em;
text-align: right;
}
.submit {
margin-left: 35%;
}
–>
Please enter your mailing address information below
<?php /* loop that displays the form */ echo ""; foreach($labels as $field => $label) { echo "echo "
$radios[0]
$radios[1]
$radios[2]
$radios[3]
echo “”;
echo "
?>
And here is my Check Script:
<?php /* Program name: checkMyForm.php * Description: Script displays a blank form and checks * all the form fields for blank fields and for legitimate content. */ 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) { $message = "You didn't fill in one or more required fields. You must enter:
- ";
/* display list of missing information */
foreach($blank_array as $value)
{
$message .= "
- $value "; } $message .= "
- ";
foreach($error_array as $value)
{
$message .= "
- $value "; } $message .= "
Thanks in advance for any help !
-Bruce Campbell