Can someone help me. My php form is giving me the same error even when the form is completely filled out and even when a field is not filled out. When the name field or any field is not filled out, it doesn’t show my error message that says: The First Name you entered does not appear to be valid.
Here is the error below I am getting on all the fields if left unfilled and even when the whole form is filled out:
We are very sorry, but there were error(s) found with the form you submitted. These errors appear below.
We are sorry, but there appears to be a problem with the form you submitted.
Please go back and fix these errors.
Here is the php code. What am I doing wrong in the code?
"; echo $error."
"; echo "Please go back and fix these errors.
"; die(); } // validation expected data exists if(!isset($_POST['first_name']) || !isset($_POST['last_name']) || !isset($_POST['company']) || !isset($_POST['address1']) || !isset($_POST['address2']) || !isset($_POST['city']) || !isset($_POST['state']) || !isset($_POST['telephone']) || !isset($_POST['email']) || !isset($_POST['ClassType'])) { died('We are sorry, but there appears to be a problem with the form you submitted.'); } $first_name = $_POST['first_name']; // required $last_name = $_POST['last_name']; // required $company = $_POST['company']; // not required $address1 = $_POST['addressl']; // required $address2 = $_POST['address2']; // not required $city = $_POST['city']; // required $state = $_POST['state']; // required $telephone = $_POST['telephone']; // required $email_from = $_POST['email']; // required $classtype = $_POST['ClassType']; // required $error_message = ""; $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/'; if(!preg_match($email_exp,$email_from)) { $error_message .= 'The Email Address you entered does not appear to be valid.
'; } $string_exp = "/^[A-Za-z .'-]+$/"; if(!preg_match($string_exp,$first_name)) { $error_message .= 'The First Name you entered does not appear to be valid.
'; } if(!preg_match($string_exp,$last_name)) { $error_message .= 'The Last Name you entered does not appear to be valid.
'; } if(strlen($address1) < 2) { $error_message .= 'The Address you entered does not appear to be valid.
'; } if(strlen($city) < 2) { $error_message .= 'The City you entered does not appear to be valid.
'; } if(strlen($state) < 2) { $error_message .= 'The State you entered does not appear to be valid.
'; } if(strlen($telephone) < 2) { $error_message .= 'The Telephone number you entered does not appear to be valid.
'; } if(strlen($ClassType) < 2) { $error_message .= 'Please select the Class you wish to attend.
'; } if(strlen($error_message) > 0) { died($error_message); } $email_message = "Form details below.\n\n"; function clean_string($string) { $bad = array("content-type","bcc:","to:","cc:","href"); return str_replace($bad,"",$string); } $email_message .= "first_name: ".clean_string($first_name)."\n"; $email_message .= "last_name: ".clean_string($last_name)."\n"; $email_message .= "company: ".clean_string($company)."\n"; $email_message .= "address1: ".clean_string($address1)."\n"; $email_message .= "address2: ".clean_string($address2)."\n"; $email_message .= "city: ".clean_string($city)."\n"; $email_message .= "state: ".clean_string($state)."\n"; $email_message .= "telephone: ".clean_string($telephone)."\n"; $email_message .= "email: ".clean_string($email_from)."\n"; $email_message .= "ClassType: ".clean_string($ClassType)."\n"; // create email headers $headers = 'From: '.$email_from."\r\n". 'Reply-To: '.$email_from."\r\n" . 'X-Mailer: PHP/' . phpversion(); @mail($email_to, $email_subject, $email_message, $headers); ?>
Your registration form has been submitted. We will be in contact with you soon. Thank you!
To return to our HMS website click HERE.
<?php}
?>
Here is the html form code:
Registration Form
<font size="2" face="Arial, Arial, Helvetica"><b>* Required field</b></font> <p> <font size="2" face="Arial, Arial, Helvetica"> <label for="first name">First Name</label> <br></font> <font face="Arial, Arial, Helvetica"> <input type="text" name="first_name" size="25" tabindex="1"
style="border:1px solid rgb(29,77,138); font-size: 10pt; color: rgb(0,0,0); background-color:rgb(100,125,160);
"> *
Last Name<br></font> <font face="Arial, Arial, Helvetica"> <input type="text" name="last_name" size="25" tabindex="2"
style="border:1px solid rgb(29,77,138); font-size: 10pt; color: rgb(0,0,0); background-color:rgb(100,125,160);
"> *
Company
Address1
*
Address2
City
*
State
*
Telephone
*
Email Address
*
Class I wish to attend: *
Medisoft Beginners Training
Medisoft Intermediate Training
Medisoft Advanced Training