Hey everyone,

Sorry if I seem a bit annoying to some people on here as well as posting something that seemed to have been solved in another post, but I cannot seem to figure out why I am getting all these error message that I've written into the processing of a form to be emailed. Also, I've inputed all of the information correctly so I shouldn't be getting any errors. Here is the code below:

<?php
include 'init.php';
protect_page();
error_reporting (E_ALL ^ E_NOTICE);
if(isset($_POST['email'])) {

    // CHANGE THE TWO LINES BELOW
    $email_to = "someonesemail@someonesemail.com";
    $email_subject = "Form";


    function died($error) {
        // your error code can go here
        echo "We are very sorry, but there were error(s) found with the form you submitted. ";
        echo "These errors appear below.<br /><br />";
        echo $error."<br /><br />";
        echo "Please go back and fix these errors.<br /><br />";
        die();
    }

    // validation expected data exists
    if(!isset($_POST['FirstName']) ||
        !isset($_POST['MiddleName']) ||
        !isset($_POST['LastName']) ||
        !isset($_POST['Email']) ||
        !isset($_POST['DateOfBirth']) ||
        !isset($_POST['PlaceOfBirth']) ||
        !isset($_POST['status']) ||
        !isset($_POST['Nationality']) ||
        !isset($_POST['CountryOfResidence']) ||
        !isset($_POST['Country_LG']) ||
        !isset($_POST['TelephoneNumber']) ||
        !isset($_POST['PermanentHomeAddress']) ||
        !isset($_POST['PassportNumber']) ||
        !isset($_POST['DateOfIssue']) ||
        !isset($_POST['ExpiryDate']) ||
        !isset($_POST['NameOfInstitutions']) ||
        !isset($_POST['Address']) ||
        !isset($_POST['City']) ||
        !isset($_POST['State']) ||
        !isset($_POST['Zip']) ||
        !isset($_POST['Telephone']) ||
        !isset($_POST['Position']) ||
        !isset($_POST['AttendanceDates']) ||
        !isset($_POST['NameOfEmployer']) ||
        !isset($_POST['Address2']) ||
        !isset($_POST['City2']) ||
        !isset($_POST['State2']) ||
        !isset($_POST['Zip2']) ||
        !isset($_POST['Telephone2']) ||
        !isset($_POST['Position2']) ||
        !isset($_POST['AttendanceDates2']) ||
        !isset($_POST['College_of_choice']) ||
        !isset($_POST['fees']) ||
        !isset($_POST['other']) ||
        !isset($_POST['work']) ||
        !isset($_POST['languages'])) {
       $feedback= "Fill out all the fields please before submitting";       
    }

    $FirstName            = $_POST["FirstName"];
    $MiddleName           = $_POST["MiddleName"];
    $LastName             = $_POST["LastName"];
    $email                = $_POST["Email"];
    $DateOfBirth          = $_POST["DateOfBirth"];
    $PlaceOfBirth         = $_POST["PlaceOfBirth"];
    $status               = $_POST["status"];
    $Nationality          = $_POST["Nationality"];
    $CountryOfResidence   = $_POST["CountryOfResidence"];
    $Country_LG           = $_POST["Country_LG"];
    $TelephoneNumber      = $_POST["TelephoneNumber"];
    $PermanentHomeAddress = $_POST["PermanentHomeAddress"];
    $PassportNumber       = $_POST["PassportNumber"];
    $DateOfIssue          = $_POST["DateOfIssue"];
    $ExpiryDate           = $_POST["ExpiryDate"];
    $NameOfInstitutions   = $_POST["NameOfInstitutions"];
    $Address              = $_POST["Address"];
    $City                 = $_POST["City"];
    $State                = $_POST["State"];
    $Zip                  = $_POST["Zip"];
    $Telephone            = $_POST["Telephone"];
    $Position             = $_POST["Position"];
    $AttendanceDates      = $_POST["AttendanceDates"];
    $NameOfEmployer       = $_POST["NameOfEmployer"];
    $Address2             = $_POST["Address2"];
    $City2                = $_POST["Cityss2"];
    $State2               = $_POST["State2"];
    $Zip2                 = $_POST["Zip2"];
    $Telephone2           = $_POST["Telephone2"];
    $Position2            = $_POST["Position2"];
    $AttendanceDates2     = $_POST["AttendanceDates2"];
    $College_of_choice    = $_POST["College_of_choice"];
    $fees                 = $_POST["fees"];
    $other                = $_POST["other"];
    $work                 = $_POST["work"];
    $languages            = $_POST["languages"];

    $error_message = "";
    $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
    $number_exp = "/^[0-9]+$/";
    $home_address = "/[a-zA-Z]*([0-9]*)[a-zA-Z]*([0-9]*)/";
  if(!preg_match($email_exp,$email)) {
    $error_message .= 'The Email Address you entered does not appear to be valid.<br />';
  }
    $string_exp = "/^[A-Za-z .'-]+$/";
  if(!preg_match($string_exp,$FirstName)) {
    $error_message .= 'The First Name you entered does not appear to be valid.<br />';
  }
  if(!preg_match($string_exp,$MiddleName)) {
    $error_message .= 'The Middle Name you entered does not appear to be valid.<br />';
  }
  if(!preg_match($string_exp,$LastName)) {
    $error_message .= 'The Last Name you entered does not appear to be valid.<br />';
  }
  if(!preg_match($number_exp,$DateOfBirth)) {
    $error_message .= 'The Date Of Birth you entered does not appear to be valid.<br />';
  }
  if(!preg_match($string_exp,$PlaceOfBirth)) {
    $error_message .= 'The Place Of Birth you entered does not appear to be valid.<br />';
  }
  if(!preg_match($string_exp,$status)) {
    $error_message .= 'The status you entered does not appear to be valid.<br />';
  }
  if(!preg_match($string_exp,$Nationality)) {
    $error_message .= 'The Nationality you entered does not appear to be valid.<br />';
  }
  if(!preg_match($string_exp,$CountryOfResidence)) {
    $error_message .= 'The Country Of Residence you selected does not appear to be valid.<br />';
  }
  if(!preg_match($string_exp,$Country_LG)) {
    $error_message .= 'The Country/LG you selected does not appear to be valid.<br />';
  }
  if(!preg_match($number_exp,$TelephoneNumber)) {
    $error_message .= 'The Telephone Number you entered does not appear to be valid.<br />';
  }
   if(!preg_match($home_address,$PermanentHomeAddress)) {
    $error_message .= 'The Permanent Home Address you entered does not appear to be valid.<br />';
  }
   if(!preg_match($number_exp,$PassportNumber)) {
    $error_message .= 'The Passport Number you entered does not appear to be valid.<br />';
  }
   if(!preg_match($number_exp,$DateOfIssue)) {
    $error_message .= 'The Date Of Issue you selected does not appear to be valid.<br />';
  }
  if(!preg_match($number_exp,$ExpiryDate)) {
    $error_message .= 'The Expiry Date you selected does not appear to be valid.<br />';
  }
  if(!preg_match($string_exp,$NameOfInstitutions)) {
    $error_message .= 'The Name Of Institutions you selected does not appear to be valid.<br />';
  }
  if(!preg_match($home_address,$Address)) {
    $error_message .= 'The Address you selected does not appear to be valid.<br />';
  }
    if(!preg_match($home_address,$City)) {
    $error_message .= 'The City you entered does not appear to be valid.<br />';
  }
    if(!preg_match($home_address,$State)) {
    $error_message .= 'The State you selected does not appear to be valid.<br />';
  }
    if(!preg_match($home_address,$Zip)) {
    $error_message .= 'The Zip you entered does not appear to be valid.<br />';
  }
  if(!preg_match($number_exp,$Telephone)) {
    $error_message .= 'The Telephone you selected does not appear to be valid.<br />';
  }
  if(!preg_match($string_exp,$Position)) {
    $error_message .= 'The Position you selected does not appear to be valid.<br />';
  }
  if(!preg_match($string_exp,$AttendanceDates)) {
    $error_message .= 'The Attendance Dates you selected does not appear to be valid.<br />';
  }
  if(!preg_match($string_exp,$NameOfEmployer)) {
    $error_message .= 'The Name Of Employer you selected does not appear to be valid.<br />';
  }
  if(!preg_match($home_address,$Address2)) {
    $error_message .= 'The Address you selected does not appear to be valid.<br />';
  }
    if(!preg_match($home_address,$City2)) {
    $error_message .= 'The City you selected does not appear to be valid.<br />';
  }
    if(!preg_match($home_address,$State2)) {
    $error_message .= 'The State you entered does not appear to be valid.<br />';
  }
    if(!preg_match($home_address,$Zip2)) {
    $error_message .= 'The Zip you entered does not appear to be valid.<br />';
  }
  if(!preg_match($number_exp,$Telephone2)) {
    $error_message .= 'The Telephone you selected does not appear to be valid.<br />';
  }
  if(!preg_match($string_exp,$Position2)) {
    $error_message .= 'The position you selected does not appear to be valid.<br />';
  }
  if(!preg_match($number_exp,$AttendanceDates2)) {
    $error_message .= 'The attendance Dates you selected does not appear to be valid.<br />';
  }
  if(!preg_match($string_exp,$College_of_choice)) {
    $error_message .= 'The College of choice you selected does not appear to be valid.<br />';
  }
  if(!preg_match($string_exp,$fees)) {
    $error_message .= 'The fee(s) amount you entered does not appear to be valid.<br />';
  }
  if(!preg_match($string_exp,$work)) {
    $error_message .= 'The work you entered does not appear to be valid.<br />';
  }
  if(empty($languages))
  {
    echo("You didn't select any languages selected.");
  }
  else
  {
    $N = count($languages);
    echo("You selected $N languages: ");
    for($i=0; $i < $N; $i++)
    {
      echo($aDoor[$i] . " ");
    }
  }

  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($Sname)."\n";
    $email_message .= "Middle Name: ".clean_string($Fname)."\n";
    $email_message .= "Last Name: ".clean_string($Mname)."\n";
    $email_message .= "Date of Birth: ".clean_string($Lname)."\n";
    $email_message .= "Place of Birth: ".clean_string($email)."\n";
    $email_message .= "Status: ".clean_string($status)."\n";
    $email_message .= "Nationality: ".clean_string($Nationality)."\n";
    $email_message .= "Country of residence: ".clean_string($CountryOfResidence)."\n";
    $email_message .= "Country/LG: ".clean_string($Country_LG)."\n";
    $email_message .= "Telephone Number: ".clean_string($TelephoneNumber)."\n";
    $email_message .= "Permanent Home Address: ".clean_string($PermanentHomeAddress)."\n";
    $email_message .= "Passport Number: ".clean_string($PassportNumber)."\n";
    $email_message .= "Date of Issue: ".clean_string($DateOfIssue)."\n";
    $email_message .= "Expiry Date: ".clean_string($ExpiryDate)."\n";
    $email_message .= "Name of Institution(s): ".clean_string($NameOfInstitutions)."\n";
    $email_message .= "Address: ".clean_string($Address)."\n";
    $email_message .= "City: ".clean_string($City)."\n";
    $email_message .= "State: ".clean_string($State)."\n";
    $email_message .= "Zip: ".clean_string($Zip)."\n";
    $email_message .= "Telephone: ".clean_string($Telephone)."\n";
    $email_message .= "Position: ".clean_string($Position)."\n";
    $email_message .= "College of choice: ".clean_string($College_of_choice)."\n";
    $email_message .= "Fees: ".clean_string($fees)."\n";
    $email_message .= "Attendance Dates: ".clean_string($AttendanceDates)."\n";
    $email_message .= "Name of Employer: ".clean_string($NameOfEmployer)."\n";
    $email_message .= "Address: ".clean_string($Address2)."\n";
    $email_message .= "City: ".clean_string($City2);
    $email_message .= "State: ".clean_string($State2);
    $email_message .= "Zip: ".clean_string($Zip2);
    $email_message .= "Telephone: ".clean_string($Telephone2)."\n";
    $email_message .= "Position: ".clean_string($Position2)."\n";
    $email_message .= "Attendance Dates: ".clean_string($AttendanceDates2)."\n";
    $email_message .= "Other: ".clean_string($other)."\n";
    $email_message .= "Work: ".clean_string($work)."\n";
    $email_message .= "Languages: ".clean_string($languages)."\n";


// create email headers
$headers = 'From: '.$email."\r\n".
'Reply-To: '.$email."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers); 
$feedback = "<b>Thanks for your submition! Your form has been sent!</b>"; 
}
?>

Here is the form code itself in html:

<form style="padding: 10px;" action="?" method="post">
            <h2><u>Personal Information</u></h2>
            <br />First Name: <input type="text" name="FirstName"><br /><br />
            Middle Name: <input type="text" name="MiddleName"><br /><br />
            Last Name: <input type="text" name="LastName"><br /><br />
            Email: <input type="text" maxlength="36" name="email"><br /><br />
            Date of Birth: <input type="text" name="DateOfBirth"><br /><br />
            Place of Birth: <input type="text" name="PlaceOfBirth"><br /><br />
            Marital Status: <select name="status">
                    <option value="select">-Select your status-</option>
                    <option value="single">Single</option>
                    <option value="married">Married</option>
                    <option value="divorced">Divorced</option>
                    <option value="widowed">Widowed</option>
                </select><br /><br />
            Nationality: <input type="text" name="Nationality"><br /><br />
            Country of Residence: <input type="text" name="CountryOfResidence"><br /><br />
            Country/LG: <input type="text" name="Country_LG"><br /><br />
            Telephone Number: <input type="text" name="TelephoneNumber"><br /><br />
            Permanent Home address: <br /><textarea name="PermanentHomeAddress"></textarea><br /><br />
            Passport No.: <input type="text" name="PassportNumber"><br /><br />
            Date of Issue: <input type="text" name="DateOfIssue"><br /><br />
            Expiry Date: <input type="text" name="ExpiryDate"><br /><br />
            <h2><u>Academic Qualification</u></h2>
            <br />Name of Institution(s): <input type="text" name="NameOfInstitutions"><br /><br />
            Address: <input type="text" name="Address"><br /><br />
            City: <input type="text" name="City"><br /><br />
            State: <select name="State">
                        <option value="select">-Select a State-</option>
                        <option value="Alabama">Alabama - AL</option>
                        <option value="Alaska">Alaska - AK</option>
                        <option value="Arizona">Arizona - AZ</option>
                        <option value="Arkansas">Arkansas - AR</option>
                        <option value="California">California - CA</option>
                        <option value="Colorado">Colorado - CO</option>
                        <option value="Conneticut">Conneticut - CT</option>
                        <option value="Delaware">Delaware - DE</option>
                        <option value="Florida">Florida - FL</option>
                        <option value="Georgia">Georgia - GA</option>
                        <option value="Hawaii">Hawaii - HI</option>
                        <option value="Idaho">Idaho - ID</option>
                        <option value="Illinois">Illinois - IL</option>
                        <option value="Indiana">Indiana - IN</option>
                        <option value="Iowa">Iowa - IA</option>
                        <option value="Kansas">Kansas - KS</option>
                        <option value="Louisiana">Louisiana - LA</option>
                        <option value="Maine">Maine - ME</option>
                        <option value="Maryland">Maryland - MD</option>
                        <option value="Massachusetts">Massachusetts - MA</option>
                        <option value="Michigan">Michigan - MI</option>
                        <option value="Minnesota">Minnesota - MN</option>
                        <option value="Mississippi">Mississippi - MS</option>
                        <option value="Missouri">Missouri - MO</option>
                        <option value="Montana">Montana - MT</option>
                        <option value="Nebraska">Nebraska - NE</option>
                        <option value="Nevada">Nevada - NV</option>
                        <option value="New Hampshire">New Hampshire - NH</option>
                        <option value="New Jersey">New Jersey - NJ</option>
                        <option value="New Mexico">New Mexico - NM</option>
                        <option value="New York">New York - NY</option>
                        <option value="North Carolina">North Carolina - NC</option>
                        <option value="North Dakota">North Dakota - ND</option>
                        <option value="Ohio">Ohio - OH</option>
                        <option value="Oklahoma">Oklahoma - OK</option>
                        <option value="Oregon">Oregon - OR</option>
                        <option value="Pennsylvania">Pennsylvania - PA</option>
                        <option value="Rhode Island">Rhode Island - RI</option>
                        <option value="South Dakota">South Dakota - SD</option>
                        <option value="Tennessee">Tennessee - TN</option>
                        <option value="Texas">Texas - TX</option>
                        <option value="Utah">Utah - UT</option>
                        <option value="Vermont">Vermont - VT</option>
                        <option value="Virginia">Virginia - VA</option>
                        <option value="Washington">Washington - WA</option>
                        <option value="West Virginia">West Virgina - WV</option>
                        <option value="Wisconsin">Wisconsin - WI</option>
                        <option value="Wyoming">Wyoming - WY</option>
                                                                </select><br /><br />
            Zip Code: <input type="text" name="zip"><br /><br />
            Telephone: <input type="text" name="Telephone"><br /><br />
            Position: <input type="text" name="Position"><br /><br />
            College University of choice: <input type="text" name="College_of_choice"><br /><br />
            Who will be responsible for your school fees?<br /><br />
            <input type="radio" value="Self" name="fees">Self<br /><br />
            <input type="radio" value="Company" name="fees">Company<br /><br />
            <input type="radio" value="Parents" name="fees">Parents<br /><br />
            <input type="radio" value="Guardian" name="fees">Guardian<br /><br />
            <input type="radio" value="Other" name="fees">Other<br /><br />
            Attendance Dates: <br /><textarea name="AttendanceDates"></textarea><br /><br />
            <h2><u>Professional Work Experience</u></h2>
            <br />Name of Employer: <input type="text" name="NameOfEmployer"><br /><br />
            Address: <input type="text" name="Address2"><br /><br />
            City: <input type="text" name="City2"><br /><br />
            State: <select name="State2">
                        <option value="select">-Select a State-</option>
                        <option value="Alabama">Alabama - AL</option>
                        <option value="Alaska">Alaska - AK</option>
                        <option value="Arizona">Arizona - AZ</option>
                        <option value="Arkansas">Arkansas - AR</option>
                        <option value="California">California - CA</option>
                        <option value="Colorado">Colorado - CO</option>
                        <option value="Conneticut">Conneticut - CT</option>
                        <option value="Delaware">Delaware - DE</option>
                        <option value="Florida">Florida - FL</option>
                        <option value="Georgia">Georgia - GA</option>
                        <option value="Hawaii">Hawaii - HI</option>
                        <option value="Idaho">Idaho - ID</option>
                        <option value="Illinois">Illinois - IL</option>
                        <option value="Indiana">Indiana - IN</option>
                        <option value="Iowa">Iowa - IA</option>
                        <option value="Kansas">Kansas - KS</option>
                        <option value="Louisiana">Louisiana - LA</option>
                        <option value="Maine">Maine - ME</option>
                        <option value="Maryland">Maryland - MD</option>
                        <option value="Massachusetts">Massachusetts - MA</option>
                        <option value="Michigan">Michigan - MI</option>
                        <option value="Minnesota">Minnesota - MN</option>
                        <option value="Mississippi">Mississippi - MS</option>
                        <option value="Missouri">Missouri - MO</option>
                        <option value="Montana">Montana - MT</option>
                        <option value="Nebraska">Nebraska - NE</option>
                        <option value="Nevada">Nevada - NV</option>
                        <option value="New Hampshire">New Hampshire - NH</option>
                        <option value="New Jersey">New Jersey - NJ</option>
                        <option value="New Mexico">New Mexico - NM</option>
                        <option value="New York">New York - NY</option>
                        <option value="North Carolina">North Carolina - NC</option>
                        <option value="North Dakota">North Dakota - ND</option>
                        <option value="Ohio">Ohio - OH</option>
                        <option value="Oklahoma">Oklahoma - OK</option>
                        <option value="Oregon">Oregon - OR</option>
                        <option value="Pennsylvania">Pennsylvania - PA</option>
                        <option value="Rhode Island">Rhode Island - RI</option>
                        <option value="South Dakota">South Dakota - SD</option>
                        <option value="Tennessee">Tennessee - TN</option>
                        <option value="Texas">Texas - TX</option>
                        <option value="Utah">Utah - UT</option>
                        <option value="Vermont">Vermont - VT</option>
                        <option value="Virginia">Virginia - VA</option>
                        <option value="Washington">Washington - WA</option>
                        <option value="West Virginia">West Virgina - WV</option>
                        <option value="Wisconsin">Wisconsin - WI</option>
                        <option value="Wyoming">Wyoming - WY</option>
                                                                </select><br /><br />
            Zip Code: <input type="text" name="zip"><br /><br />
            Telephone: <input type="text" name="Telephone2"><br /><br />
            Position: <input type="text" name="Position2"><br /><br />
            Attendance Dates: <br /><textarea name="AttendanceDates2"></textarea><br /><br />
            If you selected other, please specify: <input type="text" name="other"><br /><br />
            Are you seeking to work in the United States or Canada? <input type="text" name="work"><br /><br />
            What language are you proficient in?<br /><br />
            <input type="checkbox" name="languages[]"> English<br /><br />
            <input type="checkbox" name="languages[]"> Spanish<br /><br />
            <input type="checkbox" name="languages[]"> German<br /><br />
            <input type="checkbox" name="languages[]"> French<br /><br />
            <input type="checkbox" name="languages[]"> Japanese<br /><br />
            <input type="checkbox" name="languages[]"> Russian<br /><br />
            <input type="checkbox" name="languages[]"> Portuguese<br /><br />
            <input type="checkbox" name="languages[]"> Bengali<br /><br />
            <input type="checkbox" name="languages[]"> Arabic<br /><br />
            <input type="checkbox" name="languages[]"> Hindi-Urdu<br /><br />
            <input type="checkbox" name="languages[]"> Mandarin<br /><br />
            <input class="button" type="submit" value="submit" name="submit"> <input class="button" type="reset" value="Reset" name="reset" />
            </form>

Thanks for your time and help!

-GeneH23

I almost forgot, these are the strings that are being outputted to my screen:

"You selected 1 languages: We are very sorry, but there were error(s) found with the form you submitted. These errors appear below.

The Email Address you entered does not appear to be valid.
The Middle Name you entered does not appear to be valid.
The Date Of Birth you entered does not appear to be valid.
The Place Of Birth you entered does not appear to be valid.
The Telephone Number you entered does not appear to be valid.
The Passport Number you entered does not appear to be valid.
The Date Of Issue you selected does not appear to be valid.
The Expiry Date you selected does not appear to be valid.
The Telephone you selected does not appear to be valid.
The Attendance Dates you selected does not appear to be valid.
The Telephone you selected does not appear to be valid.
The attendance Dates you selected does not appear to be valid.

Please go back and fix these errors."

Member Avatar for LastMitch

@geneh23

There's something wrong here:

-

$email_message .= "First Name: ".clean_string($Sname)."\n";
$email_message .= "Middle Name: ".clean_string($Fname)."\n";
$email_message .= "Last Name: ".clean_string($Mname)."\n";
$email_message .= "Date of Birth: ".clean_string($Lname)."\n";
$email_message .= "Place of Birth: ".clean_string($email)."\n";

-

$FirstName = $_POST["FirstName"];
$MiddleName = $_POST["MiddleName"];
$LastName = $_POST["LastName"];
$email = $_POST["Email"];
$DateOfBirth = $_POST["DateOfBirth"];

I think you need to double check your grammer meaning put the right variable to match another variable.

For example:

$email_message .= "Date of Birth: ".clean_string($Lname)."\n";

Shouldn't it be

$email_message .= "Date of Birth: ".clean_string($DateOfBirth)."\n";

Does that make sense?

You're right @Last Mitch, That is actually how I have it in my code..I don't know why I posted the one with all the dumb errors. Everything is how you explained it should be, but I still get the same output:

"You selected 1 languages: We are very sorry, but there were error(s) found with the form you submitted. These errors appear below.

The Email Address you entered does not appear to be valid.
The Middle Name you entered does not appear to be valid.
The Date Of Birth you entered does not appear to be valid.
The Place Of Birth you entered does not appear to be valid.
The Telephone Number you entered does not appear to be valid.
The Passport Number you entered does not appear to be valid.
The Date Of Issue you selected does not appear to be valid.
The Expiry Date you selected does not appear to be valid.
The Telephone you selected does not appear to be valid.
The Attendance Dates you selected does not appear to be valid.
The Telephone you selected does not appear to be valid.
The attendance Dates you selected does not appear to be valid.

Please go back and fix these errors."

Member Avatar for LastMitch

@geneh23

There's something wrong with your Regex:

$email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
$number_exp = "/^[0-9]+$/";
$home_address = "/[a-zA-Z]*([0-9]*)[a-zA-Z]*([0-9]*)/";
$string_exp = "/^[A-Za-z .'-]+$/";

It's not going through because it's not matching. You need to find the right combination which suit each of your exp.

For example try this for your email:

$email_exp = "/([\w\-]+\@[\w\-]+\.[\w\-]+)/";

@LastMitch, I tried your example for the regular expression for the email_exp variable. Hoeever, It didn't make a difference. I still get the same output. I might also mention that I've used this script with different variable names assigned to another form and it worked perfectectly fine. I wonder why it won't work with this one..

Member Avatar for LastMitch

@geneh23

I might also mention that I've used this script with different variable names assigned to another form and it worked perfectectly fine. I wonder why it won't work with this one..

Can you please post your update code. I assume that the code above you provided is incorrect am I right?

Yes @LastMitch, You are right. This might sound like a noob question but how to I update the original code in the post?

Member Avatar for LastMitch

@geneh23

This might sound like a noob question but how to I update the original code in the post?

Update this changes regardin about this:

From this:

$email_message .= "Place of Birth: ".clean_string($email)."\n";

to this:

$email_message .= "Date of Birth: ".clean_string($DateOfBirth)."\n";

Just post the code that you have that is updated. I need to see some new errors.

<?php
include 'init.php';
protect_page();
error_reporting (E_ALL ^ E_NOTICE);
if(isset($_POST['email'])) {

    // CHANGE THE TWO LINES BELOW
    $email_to = "someonesemail@someemail.com";
    $email_subject = "Form";


    function died($error) {
        // your error code can go here
        echo "We are very sorry, but there were error(s) found with the form you submitted. ";
        echo "These errors appear below.<br /><br />";
        echo $error."<br /><br />";
        echo "Please go back and fix these errors.<br /><br />";
        die();
    }

    // validation expected data exists
    if(!isset($_POST['FirstName']) ||
        !isset($_POST['MiddleName']) ||
        !isset($_POST['LastName']) ||
        !isset($_POST['Email']) ||
        !isset($_POST['DateOfBirth']) ||
        !isset($_POST['PlaceOfBirth']) ||
        !isset($_POST['status']) ||
        !isset($_POST['Nationality']) ||
        !isset($_POST['CountryOfResidence']) ||
        !isset($_POST['Country_LG']) ||
        !isset($_POST['TelephoneNumber']) ||
        !isset($_POST['PermanentHomeAddress']) ||
        !isset($_POST['PassportNumber']) ||
        !isset($_POST['DateOfIssue']) ||
        !isset($_POST['ExpiryDate']) ||
        !isset($_POST['NameOfInstitutions']) ||
        !isset($_POST['Address']) ||
        !isset($_POST['City']) ||
        !isset($_POST['State']) ||
        !isset($_POST['Zip']) ||
        !isset($_POST['Telephone']) ||
        !isset($_POST['Position']) ||
        !isset($_POST['AttendanceDates']) ||
        !isset($_POST['NameOfEmployer']) ||
        !isset($_POST['Address2']) ||
        !isset($_POST['City2']) ||
        !isset($_POST['State2']) ||
        !isset($_POST['Zip2']) ||
        !isset($_POST['Telephone2']) ||
        !isset($_POST['Position2']) ||
        !isset($_POST['AttendanceDates2']) ||
        !isset($_POST['College_of_choice']) ||
        !isset($_POST['fees']) ||
        !isset($_POST['other']) ||
        !isset($_POST['work']) ||
        !isset($_POST['languages'])) {
       $feedback= "Fill out all the fields please before submitting";       
    }

    $FirstName            = $_POST["FirstName"];
    $MiddleName           = $_POST["MiddleName"];
    $LastName             = $_POST["LastName"];
    $email                = $_POST["Email"];
    $DateOfBirth          = $_POST["DateOfBirth"];
    $PlaceOfBirth         = $_POST["PlaceOfBirth"];
    $status               = $_POST["status"];
    $Nationality          = $_POST["Nationality"];
    $CountryOfResidence   = $_POST["CountryOfResidence"];
    $Country_LG           = $_POST["Country_LG"];
    $TelephoneNumber      = $_POST["TelephoneNumber"];
    $PermanentHomeAddress = $_POST["PermanentHomeAddress"];
    $PassportNumber       = $_POST["PassportNumber"];
    $DateOfIssue          = $_POST["DateOfIssue"];
    $ExpiryDate           = $_POST["ExpiryDate"];
    $NameOfInstitutions   = $_POST["NameOfInstitutions"];
    $Address              = $_POST["Address"];
    $City                 = $_POST["City"];
    $State                = $_POST["State"];
    $Zip                  = $_POST["Zip"];
    $Telephone            = $_POST["Telephone"];
    $Position             = $_POST["Position"];
    $AttendanceDates      = $_POST["AttendanceDates"];
    $NameOfEmployer       = $_POST["NameOfEmployer"];
    $Address2             = $_POST["Address2"];
    $City2                = $_POST["Cityss2"];
    $State2               = $_POST["State2"];
    $Zip2                 = $_POST["Zip2"];
    $Telephone2           = $_POST["Telephone2"];
    $Position2            = $_POST["Position2"];
    $AttendanceDates2     = $_POST["AttendanceDates2"];
    $College_of_choice    = $_POST["College_of_choice"];
    $fees                 = $_POST["fees"];
    $other                = $_POST["other"];
    $work                 = $_POST["work"];
    $languages            = $_POST["languages"];

    $error_message = "";
    $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
    $number_exp = "/^[0-9]+$/";
    $home_address = "/[a-zA-Z]*([0-9]*)[a-zA-Z]*([0-9]*)/";
  if(!preg_match($email_exp,$email)) {
    $error_message .= 'The Email Address you entered does not appear to be valid.<br />';
  }
    $string_exp = "/^[A-Za-z .'-]+$/";
  if(!preg_match($string_exp,$FirstName)) {
    $error_message .= 'The First Name you entered does not appear to be valid.<br />';
  }
  if(!preg_match($string_exp,$MiddleName)) {
    $error_message .= 'The Middle Name you entered does not appear to be valid.<br />';
  }
  if(!preg_match($string_exp,$LastName)) {
    $error_message .= 'The Last Name you entered does not appear to be valid.<br />';
  }
  if(!preg_match($number_exp,$DateOfBirth)) {
    $error_message .= 'The Date Of Birth you entered does not appear to be valid.<br />';
  }
  if(!preg_match($string_exp,$PlaceOfBirth)) {
    $error_message .= 'The Place Of Birth you entered does not appear to be valid.<br />';
  }
  if(!preg_match($string_exp,$status)) {
    $error_message .= 'The status you entered does not appear to be valid.<br />';
  }
  if(!preg_match($string_exp,$Nationality)) {
    $error_message .= 'The Nationality you entered does not appear to be valid.<br />';
  }
  if(!preg_match($string_exp,$CountryOfResidence)) {
    $error_message .= 'The Country Of Residence you selected does not appear to be valid.<br />';
  }
  if(!preg_match($string_exp,$Country_LG)) {
    $error_message .= 'The Country/LG you selected does not appear to be valid.<br />';
  }
  if(!preg_match($number_exp,$TelephoneNumber)) {
    $error_message .= 'The Telephone Number you entered does not appear to be valid.<br />';
  }
   if(!preg_match($home_address,$PermanentHomeAddress)) {
    $error_message .= 'The Permanent Home Address you entered does not appear to be valid.<br />';
  }
   if(!preg_match($number_exp,$PassportNumber)) {
    $error_message .= 'The Passport Number you entered does not appear to be valid.<br />';
  }
   if(!preg_match($number_exp,$DateOfIssue)) {
    $error_message .= 'The Date Of Issue you selected does not appear to be valid.<br />';
  }
  if(!preg_match($number_exp,$ExpiryDate)) {
    $error_message .= 'The Expiry Date you selected does not appear to be valid.<br />';
  }
  if(!preg_match($string_exp,$NameOfInstitutions)) {
    $error_message .= 'The Name Of Institutions you selected does not appear to be valid.<br />';
  }
  if(!preg_match($home_address,$Address)) {
    $error_message .= 'The Address you selected does not appear to be valid.<br />';
  }
    if(!preg_match($home_address,$City)) {
    $error_message .= 'The City you entered does not appear to be valid.<br />';
  }
    if(!preg_match($home_address,$State)) {
    $error_message .= 'The State you selected does not appear to be valid.<br />';
  }
    if(!preg_match($home_address,$Zip)) {
    $error_message .= 'The Zip you entered does not appear to be valid.<br />';
  }
  if(!preg_match($number_exp,$Telephone)) {
    $error_message .= 'The Telephone you selected does not appear to be valid.<br />';
  }
  if(!preg_match($string_exp,$Position)) {
    $error_message .= 'The Position you selected does not appear to be valid.<br />';
  }
  if(!preg_match($string_exp,$AttendanceDates)) {
    $error_message .= 'The Attendance Dates you selected does not appear to be valid.<br />';
  }
  if(!preg_match($string_exp,$NameOfEmployer)) {
    $error_message .= 'The Name Of Employer you selected does not appear to be valid.<br />';
  }
  if(!preg_match($home_address,$Address2)) {
    $error_message .= 'The Address you selected does not appear to be valid.<br />';
  }
    if(!preg_match($home_address,$City2)) {
    $error_message .= 'The City you selected does not appear to be valid.<br />';
  }
    if(!preg_match($home_address,$State2)) {
    $error_message .= 'The State you entered does not appear to be valid.<br />';
  }
    if(!preg_match($home_address,$Zip2)) {
    $error_message .= 'The Zip you entered does not appear to be valid.<br />';
  }
  if(!preg_match($number_exp,$Telephone2)) {
    $error_message .= 'The Telephone you selected does not appear to be valid.<br />';
  }
  if(!preg_match($string_exp,$Position2)) {
    $error_message .= 'The position you selected does not appear to be valid.<br />';
  }
  if(!preg_match($number_exp,$AttendanceDates2)) {
    $error_message .= 'The attendance Dates you selected does not appear to be valid.<br />';
  }
  if(!preg_match($string_exp,$College_of_choice)) {
    $error_message .= 'The College of choice you selected does not appear to be valid.<br />';
  }
  if(!preg_match($string_exp,$fees)) {
    $error_message .= 'The fee(s) amount you entered does not appear to be valid.<br />';
  }
  if(!preg_match($string_exp,$work)) {
    $error_message .= 'The work you entered does not appear to be valid.<br />';
  }
  if(empty($languages))
  {
    echo("You didn't select any languages selected.");
  }
  else
  {
    $N = count($languages);
    echo("You selected $N languages: ");
    for($i=0; $i < $N; $i++)
    {
      echo($aDoor[$i] . " ");
    }
  }

  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($FirstName)."\n";
    $email_message .= "Middle Name: ".clean_string($MiddleName)."\n";
    $email_message .= "Last Name: ".clean_string($LastName)."\n";
    $email_message .= "Date of Birth: ".clean_string($DateOfBirth)."\n";
    $email_message .= "Place of Birth: ".clean_string($PlaceOfBirth)."\n";
    $email_message .= "Status: ".clean_string($status)."\n";
    $email_message .= "Nationality: ".clean_string($Nationality)."\n";
    $email_message .= "Country of residence: ".clean_string($CountryOfResidence)."\n";
    $email_message .= "Country/LG: ".clean_string($Country_LG)."\n";
    $email_message .= "Telephone Number: ".clean_string($TelephoneNumber)."\n";
    $email_message .= "Permanent Home Address: ".clean_string($PermanentHomeAddress)."\n";
    $email_message .= "Passport Number: ".clean_string($PassportNumber)."\n";
    $email_message .= "Date of Issue: ".clean_string($DateOfIssue)."\n";
    $email_message .= "Expiry Date: ".clean_string($ExpiryDate)."\n";
    $email_message .= "Name of Institution(s): ".clean_string($NameOfInstitutions)."\n";
    $email_message .= "Address: ".clean_string($Address)."\n";
    $email_message .= "City: ".clean_string($City)."\n";
    $email_message .= "State: ".clean_string($State)."\n";
    $email_message .= "Zip: ".clean_string($Zip)."\n";
    $email_message .= "Telephone: ".clean_string($Telephone)."\n";
    $email_message .= "Position: ".clean_string($Position)."\n";
    $email_message .= "College of choice: ".clean_string($College_of_choice)."\n";
    $email_message .= "Fees: ".clean_string($fees)."\n";
    $email_message .= "Attendance Dates: ".clean_string($AttendanceDates)."\n";
    $email_message .= "Name of Employer: ".clean_string($NameOfEmployer)."\n";
    $email_message .= "Address: ".clean_string($Address2)."\n";
    $email_message .= "City: ".clean_string($City2);
    $email_message .= "State: ".clean_string($State2);
    $email_message .= "Zip: ".clean_string($Zip2);
    $email_message .= "Telephone: ".clean_string($Telephone2)."\n";
    $email_message .= "Position: ".clean_string($Position2)."\n";
    $email_message .= "Attendance Dates: ".clean_string($AttendanceDates2)."\n";
    $email_message .= "Other: ".clean_string($other)."\n";
    $email_message .= "Work: ".clean_string($work)."\n";
    $email_message .= "Languages: ".clean_string($languages)."\n";


// create email headers
$headers = 'From: '.$email."\r\n".
'Reply-To: '.$email."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers); 
$feedback = "<b>Thanks for your submition! Your form has been sent!</b>"; 
}
?>

html form:

<form style="padding: 10px;" action="?" method="post">
            <h2><u>Personal Information</u></h2>
            <br />First Name: <input type="text" name="FirstName"><br /><br />
            Middle Name: <input type="text" name="MiddleName"><br /><br />
            Last Name: <input type="text" name="LastName"><br /><br />
            Email: <input type="text" maxlength="36" name="email"><br /><br />
            Date of Birth: <input type="text" name="DateOfBirth"><br /><br />
            Place of Birth: <input type="text" name="PlaceOfBirth"><br /><br />
            Marital Status: <select name="status">
                    <option value="select">-Select your status-</option>
                    <option value="single">Single</option>
                    <option value="married">Married</option>
                    <option value="divorced">Divorced</option>
                    <option value="widowed">Widowed</option>
                </select><br /><br />
            Nationality: <input type="text" name="Nationality"><br /><br />
            Country of Residence: <input type="text" name="CountryOfResidence"><br /><br />
            Country/LG: <input type="text" name="Country_LG"><br /><br />
            Telephone Number: <input type="text" name="TelephoneNumber"><br /><br />
            Permanent Home address: <br /><textarea name="PermanentHomeAddress"></textarea><br /><br />
            Passport No.: <input type="text" name="PassportNumber"><br /><br />
            Date of Issue: <input type="text" name="DateOfIssue"><br /><br />
            Expiry Date: <input type="text" name="ExpiryDate"><br /><br />
            <h2><u>Academic Qualification</u></h2>
            <br />Name of Institution(s): <input type="text" name="NameOfInstitutions"><br /><br />
            Address: <input type="text" name="Address"><br /><br />
            City: <input type="text" name="City"><br /><br />
            State: <select name="State">
                        <option value="select">-Select a State-</option>
                        <option value="Alabama">Alabama - AL</option>
                        <option value="Alaska">Alaska - AK</option>
                        <option value="Arizona">Arizona - AZ</option>
                        <option value="Arkansas">Arkansas - AR</option>
                        <option value="California">California - CA</option>
                        <option value="Colorado">Colorado - CO</option>
                        <option value="Conneticut">Conneticut - CT</option>
                        <option value="Delaware">Delaware - DE</option>
                        <option value="Florida">Florida - FL</option>
                        <option value="Georgia">Georgia - GA</option>
                        <option value="Hawaii">Hawaii - HI</option>
                        <option value="Idaho">Idaho - ID</option>
                        <option value="Illinois">Illinois - IL</option>
                        <option value="Indiana">Indiana - IN</option>
                        <option value="Iowa">Iowa - IA</option>
                        <option value="Kansas">Kansas - KS</option>
                        <option value="Louisiana">Louisiana - LA</option>
                        <option value="Maine">Maine - ME</option>
                        <option value="Maryland">Maryland - MD</option>
                        <option value="Massachusetts">Massachusetts - MA</option>
                        <option value="Michigan">Michigan - MI</option>
                        <option value="Minnesota">Minnesota - MN</option>
                        <option value="Mississippi">Mississippi - MS</option>
                        <option value="Missouri">Missouri - MO</option>
                        <option value="Montana">Montana - MT</option>
                        <option value="Nebraska">Nebraska - NE</option>
                        <option value="Nevada">Nevada - NV</option>
                        <option value="New Hampshire">New Hampshire - NH</option>
                        <option value="New Jersey">New Jersey - NJ</option>
                        <option value="New Mexico">New Mexico - NM</option>
                        <option value="New York">New York - NY</option>
                        <option value="North Carolina">North Carolina - NC</option>
                        <option value="North Dakota">North Dakota - ND</option>
                        <option value="Ohio">Ohio - OH</option>
                        <option value="Oklahoma">Oklahoma - OK</option>
                        <option value="Oregon">Oregon - OR</option>
                        <option value="Pennsylvania">Pennsylvania - PA</option>
                        <option value="Rhode Island">Rhode Island - RI</option>
                        <option value="South Dakota">South Dakota - SD</option>
                        <option value="Tennessee">Tennessee - TN</option>
                        <option value="Texas">Texas - TX</option>
                        <option value="Utah">Utah - UT</option>
                        <option value="Vermont">Vermont - VT</option>
                        <option value="Virginia">Virginia - VA</option>
                        <option value="Washington">Washington - WA</option>
                        <option value="West Virginia">West Virgina - WV</option>
                        <option value="Wisconsin">Wisconsin - WI</option>
                        <option value="Wyoming">Wyoming - WY</option>
                                                                </select><br /><br />
            Zip Code: <input type="text" name="zip"><br /><br />
            Telephone: <input type="text" name="Telephone"><br /><br />
            Position: <input type="text" name="Position"><br /><br />
            College University of choice: <input type="text" name="College_of_choice"><br /><br />
            Who will be responsible for your school fees?<br /><br />
            <input type="radio" value="Self" name="fees">Self<br /><br />
            <input type="radio" value="Company" name="fees">Company<br /><br />
            <input type="radio" value="Parents" name="fees">Parents<br /><br />
            <input type="radio" value="Guardian" name="fees">Guardian<br /><br />
            <input type="radio" value="Other" name="fees">Other<br /><br />
            Attendance Dates: <br /><textarea name="AttendanceDates"></textarea><br /><br />
            <h2><u>Professional Work Experience</u></h2>
            <br />Name of Employer: <input type="text" name="NameOfEmployer"><br /><br />
            Address: <input type="text" name="Address2"><br /><br />
            City: <input type="text" name="City2"><br /><br />
            State: <select name="State2">
                        <option value="select">-Select a State-</option>
                        <option value="Alabama">Alabama - AL</option>
                        <option value="Alaska">Alaska - AK</option>
                        <option value="Arizona">Arizona - AZ</option>
                        <option value="Arkansas">Arkansas - AR</option>
                        <option value="California">California - CA</option>
                        <option value="Colorado">Colorado - CO</option>
                        <option value="Conneticut">Conneticut - CT</option>
                        <option value="Delaware">Delaware - DE</option>
                        <option value="Florida">Florida - FL</option>
                        <option value="Georgia">Georgia - GA</option>
                        <option value="Hawaii">Hawaii - HI</option>
                        <option value="Idaho">Idaho - ID</option>
                        <option value="Illinois">Illinois - IL</option>
                        <option value="Indiana">Indiana - IN</option>
                        <option value="Iowa">Iowa - IA</option>
                        <option value="Kansas">Kansas - KS</option>
                        <option value="Louisiana">Louisiana - LA</option>
                        <option value="Maine">Maine - ME</option>
                        <option value="Maryland">Maryland - MD</option>
                        <option value="Massachusetts">Massachusetts - MA</option>
                        <option value="Michigan">Michigan - MI</option>
                        <option value="Minnesota">Minnesota - MN</option>
                        <option value="Mississippi">Mississippi - MS</option>
                        <option value="Missouri">Missouri - MO</option>
                        <option value="Montana">Montana - MT</option>
                        <option value="Nebraska">Nebraska - NE</option>
                        <option value="Nevada">Nevada - NV</option>
                        <option value="New Hampshire">New Hampshire - NH</option>
                        <option value="New Jersey">New Jersey - NJ</option>
                        <option value="New Mexico">New Mexico - NM</option>
                        <option value="New York">New York - NY</option>
                        <option value="North Carolina">North Carolina - NC</option>
                        <option value="North Dakota">North Dakota - ND</option>
                        <option value="Ohio">Ohio - OH</option>
                        <option value="Oklahoma">Oklahoma - OK</option>
                        <option value="Oregon">Oregon - OR</option>
                        <option value="Pennsylvania">Pennsylvania - PA</option>
                        <option value="Rhode Island">Rhode Island - RI</option>
                        <option value="South Dakota">South Dakota - SD</option>
                        <option value="Tennessee">Tennessee - TN</option>
                        <option value="Texas">Texas - TX</option>
                        <option value="Utah">Utah - UT</option>
                        <option value="Vermont">Vermont - VT</option>
                        <option value="Virginia">Virginia - VA</option>
                        <option value="Washington">Washington - WA</option>
                        <option value="West Virginia">West Virgina - WV</option>
                        <option value="Wisconsin">Wisconsin - WI</option>
                        <option value="Wyoming">Wyoming - WY</option>
                                                                </select><br /><br />
            Zip Code: <input type="text" name="zip"><br /><br />
            Telephone: <input type="text" name="Telephone2"><br /><br />
            Position: <input type="text" name="Position2"><br /><br />
            Attendance Dates: <br /><textarea name="AttendanceDates2"></textarea><br /><br />
            If you selected other, please specify: <input type="text" name="other"><br /><br />
            Are you seeking to work in the United States or Canada? <input type="text" name="work"><br /><br />
            What language are you proficient in?<br /><br />
            <input type="checkbox" name="languages[]"> English<br /><br />
            <input type="checkbox" name="languages[]"> Spanish<br /><br />
            <input type="checkbox" name="languages[]"> German<br /><br />
            <input type="checkbox" name="languages[]"> French<br /><br />
            <input type="checkbox" name="languages[]"> Japanese<br /><br />
            <input type="checkbox" name="languages[]"> Russian<br /><br />
            <input type="checkbox" name="languages[]"> Portuguese<br /><br />
            <input type="checkbox" name="languages[]"> Bengali<br /><br />
            <input type="checkbox" name="languages[]"> Arabic<br /><br />
            <input type="checkbox" name="languages[]"> Hindi-Urdu<br /><br />
            <input type="checkbox" name="languages[]"> Mandarin<br /><br />
            <input class="button" type="submit" value="submit" name="submit"> <input class="button" type="reset" value="Reset" name="reset" />
            </form>

Shouldn't line 99 => $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';

be wrapped in double quotes not single?

$email_exp = "/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/";

@Squidge - either way, the end result is still the same

Member Avatar for LastMitch

@geneh23

My question is a very simple question. Why do you have so many stuff in this email form?

This is wrong:

<input type="checkbox" name="languages[]"> English<br /><br />

There shouldn't be this [].

I gave you a link to test and modify it

http://www.freecontactform.com/email_form.php

I might also mention that I've used this script with different variable names assigned to another form and it worked perfectectly fine. I wonder why it won't work with this one..

Like what Squidge

put double quotes:

$email_exp = "/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/";

Since you test this code already and works? Are you sure? Right now base on the code you didn't change much. The issue is still here:

$email_exp = "/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/";
$number_exp = "/^[0-9]+$/";
$home_address = "/[a-zA-Z]*([0-9]*)[a-zA-Z]*([0-9]*)/";
$string_exp = "/^[A-Za-z .'-]+$/";

alright..here is the other script that I had with another form that went with the script. This form works and outputs the successs message

"Thanks for your submition! Your form has been sent!"

<?php
include 'init.php';
protect_page();
error_reporting (E_ALL ^ E_NOTICE);
if(isset($_POST['email'])) {

    // CHANGE THE TWO LINES BELOW
    $email_to = "someones@email.com";
    $email_subject = "Form";


    function died($error) {
        // your error code can go here
        echo "We are very sorry, but there were error(s) found with the form you submitted. ";
        echo "These errors appear below.<br /><br />";
        echo $error."<br /><br />";
        echo "Please go back and fix these errors.<br /><br />";
        die();
    }

    // validation expected data exists
    if(!isset($_POST['Sname']) ||
        !isset($_POST['Fname']) ||
        !isset($_POST['Mname']) ||
        !isset($_POST['Lname']) ||
        !isset($_POST['email']) ||
        !isset($_POST['history']) ||
        !isset($_POST['age']) ||
        !isset($_POST['sex']) ||
        !isset($_POST['country']) ||
        !isset($_POST['SchoolsAttended']) ||
        !isset($_POST['CriminalRecord']) ||
        !isset($_POST['record']) ||
        !isset($_POST['status'])) {
       $feedback="Fill out all the fields please before submitting";       
    }

    $Sname = $_POST["Sname"];
    $Fname = $_POST["Fname"];
    $Mname = $_POST["Mname"];
    $Lname = $_POST["Lname"];
    $email = $_POST["email"];
    $history = $_POST["history"];
    $age = $_POST["age"];
    $sex = $_POST["sex"];
    $country = $_POST["country"];
    $SchoolsAttended = $_POST["SchoolsAttended"];
    $CriminalRecord = $_POST["CriminalRecord"];
    $record = $_POST["record"];
    $status = $_POST["status"];

    $error_message = "";
    $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
    $number_exp = "/^[0-9]+$/";
  if(!preg_match($email_exp,$email)) {
    $error_message .= 'The Email Address you entered does not appear to be valid.<br />';
  }
    $string_exp = "/^[A-Za-z .'-]+$/";
  if(!preg_match($string_exp,$Sname)) {
    $error_message .= 'The Sir Name you entered does not appear to be valid.<br />';
  }
  if(!preg_match($string_exp,$Fname)) {
    $error_message .= 'The First Name you entered does not appear to be valid.<br />';
  }
  if(!preg_match($string_exp,$Mname)) {
    $error_message .= 'The Middle Name you entered does not appear to be valid.<br />';
  }
  if(!preg_match($string_exp,$Lname)) {
    $error_message .= 'The Last Name you entered does not appear to be valid.<br />';
  }
  if(!preg_match($string_exp,$history)) {
    $error_message .= 'The history you entered does not appear to be valid.<br />';
  }
  if(!preg_match($number_exp,$age)) {
    $error_message .= 'The age you entered does not appear to be valid.<br />';
  }
  if(!preg_match($string_exp,$sex)) {
    $error_message .= 'The gender you selected does not appear to be valid.<br />';
  }
  if(!preg_match($string_exp,$country)) {
    $error_message .= 'The country you selected does not appear to be valid.<br />';
  }
  if(!preg_match($string_exp,$SchoolsAttended)) {
    $error_message .= 'The school you entered does not appear to be valid.<br />';
  }
   if(!preg_match($string_exp,$CriminalRecord)) {
    $error_message .= 'The criminal record you entered does not appear to be valid.<br />';
  }
   if(!preg_match($string_exp,$record)) {
    $error_message .= 'The record you entered does not appear to be valid.<br />';
  }
   if(!preg_match($string_exp,$status)) {
    $error_message .= 'The status you selected does not appear to be valid.<br />';
  }
  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 .= "Sir Name: ".clean_string($Sname)."\n";
    $email_message .= "First Name: ".clean_string($Fname)."\n";
    $email_message .= "Middle Name: ".clean_string($Mname)."\n";
    $email_message .= "Last Name: ".clean_string($Lname)."\n";
    $email_message .= "Email: ".clean_string($email)."\n";
    $email_message .= "History: ".clean_string($history)."\n";
    $email_message .= "Age: ".clean_string($age)."\n";
    $email_message .= "Sex: ".clean_string($sex)."\n";
    $email_message .= "Country: ".clean_string($country)."\n";
    $email_message .= "Schools Attended: ".clean_string($SchoolsAttended)."\n";
    $email_message .= "Criminal Record: ".clean_string($CriminalRecord)."\n";
    $email_message .= "If yes was selected, list of details: ".clean_string($record)."\n";
    $email_message .= "Status: ".clean_string($status)."\n";


// create email headers
$headers = 'From: '.$email."\r\n".
'Reply-To: '.$email."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers); 
$feedback = "<b>Thanks for your submition! Your form has been sent!</b>"; 
}
?>
<html>
<body>
<p id="feedback"><?php echo $feedback; ?></p>
                <form style="padding: 10px;" method="post" action="?">
Surname: <input type="text" maxlength="12" name="Sname"><br /><br />
First Name: <input type="text" maxlength="12" name="Fname"><br /><br />
Middle Name: <input type="text" maxlength="12" name="Mname"><br /><br />
Last Name: <input type="text" maxlength="36" name="Lname"><br /><br />
Email: <input type="text" maxlength="36" name="email"><br /><br />
History: <input type="text" maxlength="50" name="history"><br /><br />
Age: <input type="text" size="1" maxlength="2" name="age"><br /><br />
Sex: <input type="radio" value="Male" name="sex">Male<input type="radio" value="Female" name="sex">Female<br /><br />
Country of Origin: <select name="country">
                    <option value="Select">-Select a Country-</option>
                    <option value="United States">United States</option>
                    <option value="Africa">Africa</option>
                    <option value="Canada">Canada</option>
                </select><br /><br />
Schools Attended: <input type="text" name="SchoolsAttended"><br /><br />
Do you have a criminal record? <input type="radio" value="yes" name="CriminalRecord">Yes <input type="radio" value="no" name="CriminalRecord">No<br /><br />
If yes was selected, please list them in the field provided: <input type="text" name="record"><br /><br />
 Marital Status: <select name="status">
                    <option value="select">-Select your status-</option>
                    <option value="single">Single</option>
                    <option value="married">Married</option>
                    <option value="divorced">Divorced</option>
                    <option value="widowed">Widowed</option>
                </select><br /><br />
<input class="button" type="submit" value="submit" name="submit"> <input class="button" type="reset" value="Reset" name="reset" />
</form>
</body>
</html>

Since I used the same code, with different variables, It should work without a problem..but that's obviously not the case...

Member Avatar for LastMitch

@geneh23

Since I used the same code, with different variables, It should work without a problem..but that's obviously not the case...

If this code works then it's good. But the other one you posted it's not good.

Why are you putting so many stuff in your email form? Why is there a language section? There's a big difference between an email form and a form. Your data is consisted as a form not a email form. I never seen a email form like this. This is more like a form.

Well yes it is a "form" but it's purpose is for the data to be sent as an email based from the form itself. Is there a different way to do this? Sorry for my lack of knowledge if this is the case..

Member Avatar for LastMitch

@geneh23

Well yes it is a "form" but it's purpose is for the data to be sent as an email based from the form itself.

You're right but why? Why so many stuffs you add like 23 lines new of POST?

From this:

$Sname = $_POST["Sname"];
$Fname = $_POST["Fname"];
$Mname = $_POST["Mname"];
$Lname = $_POST["Lname"];
$email = $_POST["email"];
$history = $_POST["history"];
$age = $_POST["age"];
$sex = $_POST["sex"];
$country = $_POST["country"];
$SchoolsAttended = $_POST["SchoolsAttended"];
$CriminalRecord = $_POST["CriminalRecord"];
$record = $_POST["record"];
$status = $_POST["status"];

to this:

$FirstName = $_POST["FirstName"];
$MiddleName = $_POST["MiddleName"];
$LastName = $_POST["LastName"];
$email = $_POST["Email"];
$DateOfBirth = $_POST["DateOfBirth"];
$PlaceOfBirth = $_POST["PlaceOfBirth"];
$status = $_POST["status"];
$Nationality = $_POST["Nationality"];
$CountryOfResidence = $_POST["CountryOfResidence"];
$Country_LG = $_POST["Country_LG"];
$TelephoneNumber = $_POST["TelephoneNumber"];
$PermanentHomeAddress = $_POST["PermanentHomeAddress"];
$PassportNumber = $_POST["PassportNumber"];
$DateOfIssue = $_POST["DateOfIssue"];
$ExpiryDate = $_POST["ExpiryDate"];
$NameOfInstitutions = $_POST["NameOfInstitutions"];
$Address = $_POST["Address"];
$City = $_POST["City"];
$State = $_POST["State"];
$Zip = $_POST["Zip"];
$Telephone = $_POST["Telephone"];
$Position = $_POST["Position"];
$AttendanceDates = $_POST["AttendanceDates"];
$NameOfEmployer = $_POST["NameOfEmployer"];
$Address2 = $_POST["Address2"];
$City2 = $_POST["Cityss2"];
$State2 = $_POST["State2"];
$Zip2 = $_POST["Zip2"];
$Telephone2 = $_POST["Telephone2"];
$Position2 = $_POST["Position2"];
$AttendanceDates2 = $_POST["AttendanceDates2"];
$College_of_choice = $_POST["College_of_choice"];
$fees = $_POST["fees"];
$other = $_POST["other"];
$work = $_POST["work"];
$languages = $_POST["languages"];

Is there a different way to do this?

Yes, when a client fill out the form on the email and submitted, then it goes to your email box directly because it's from a email. Form does that too it also goes to the email if you set it that way. The form is actually a webpage when your clients fill out the info and submit the form and more likely it will go to your email box too.

yes, this is my goal. The form is on a web page that will be submitted to an email.

and It's for a client of mine who wants information from people in order to obtain access to a site..so It's essentially a registration form but it's an evaluation form according to that person and this is the way they want it..

I looked at that link and read the page. Does that link just show the validation? I didn't see anything about sending the data to an email.

Your form has name="email" but script has $_POST['Email'] make sure both have the same capatalization. Change your regex expression for strings to:
#[^a-z .'-]#i

And for numbers:
#[^0-9]#

@GliderPilot, I made everything the same and changed the regex expression and I still get the same result.

If you change your error messages to display the value provided what does it output?

i.e.

$error_message .= "The Middle Name '$MiddleName' does not appear to be valid.<br />";

Just thought of something. Are you using any special characters, non-english letters? If so that will cause that regex to fail.

Member Avatar for LastMitch

@geneh23

I didn't see anything about sending the data to an email.

This is the file:

Let's call it info.php

This file goes here:

<form method="post" action="info.php">
The examples code from the link goes here.
</form>

This is what contain in the info.php

<?php
$name = $_POST['name'];
$email = $_POST['email'];
$address = $_POST["address"];
$howMany = $_POST["howMany"];
$favFruit = $_POST["favFruit"];
$formcontent= "From: $name \n <-> \n Message: $message";
$recipient = "geneh23@geneh.com";
$subject = "Message";
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
?>

You can now test the code with this file.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.