I have been trying for several days to get some fields to be required. For example, I want to get the descendants first name, middle name, and surname, to be required. I can’t seem to get it to work right. I could use some help as to what I am doing wrong. I have tried so many things I can’t even remember them all. Here is my current code.
[php]<?php
$error = “”;
$descendant_first_name = $descendant_middle_name = $descendant_surname = “”;
/* Check to see if the html was sent via $_POST /
if ($_SERVER[“REQUEST_METHOD”] == “POST”){
/ If true we continue on with the script /
/ Subject and Email Variables */
$emailSubject = '2017 Windemuth Family Reunion Registration Form';
/* Gathering Data Variables */
/*compare the email address */
if($_POST['email'] != $_POST['confirm']) {
#set error...
$error .= 'The email addresses do not match, please correct and submit again<br>';
}
if (empty($_POST["descendant_first_name"])) {
$error .= "Your first name is required<br>";
$Descendant_First_Name = "";
} else {
$Descendant_First_Name = test_input($_POST["descendant_first_name"]);
}
if (empty($_POST["descendant_middle_name"])) {
$error .= "Your middle name is required<br>";
$Descendant_Middle_Name = "";
} else {
$Descendant_Middle_Name = test_input($_POST["descendant_middle_name"]);
}
if (empty($_POST["descendant_surname"])) {
$error .= "Your surname is required<br>";
$Descendant_Surname = "";
} else {
$Descendant_Surname = test_input($_POST["descendant_surname"]);
}
$S_SO_First_Name = $_POST['s_so_first_name'];
$S_SO_Middle_Name = $_POST['s_so_middle_name'];
$S_SO_Last_Name = $_POST['s_so_last_name'];
$Child1_First_Name = $_POST['child1_first_name'];
$Child1_Middle_Name = $_POST['child1_middle_name'];
$Child1_Last_Name = $_POST['child1_last_name'];
$Child2_First_Name = $_POST['child2_first_name'];
$Child2_Middle_Name = $_POST['child2_middle_name'];
$Child2_Last_Name = $_POST['child2_last_name'];
$Child3_First_Name = $_POST['child3_first_name'];
$Child3_Middle_Name = $_POST['child3_middle_name'];
$Child3_Last_Name = $_POST['child3_last_name'];
$Child4_First_Name = $_POST['child4_first_name'];
$Child4_Middle_Name = $_POST['child4_middle_name'];
$Child4_Last_Name = $_POST['child4_last_name'];
$Street = $_POST['street'];
$City = $_POST['city'];
$StateProvince = $_POST['stateprovince'];
$PostalCode = $_POST['postalcode'];
$Phone = $_POST['phone'];
$Email = $_POST['email'];
$Confirm = $_POST['confirm'];
$Adults = $_POST['adults'];
$Children = $_POST['children'];
$RegistrationFee = $_POST['registrationfee'];
$Comments = $_POST['comments'];
$webMaster = $Descendant.'<[email protected]>';
$immigrant="";
foreach($_POST["immigrant"] as $option){
$immigrant .= $option;
}
$body = <<<EOD
<br><hr><br>
Descendant_First_Name: $Descendant_First_Name <br>
Descendant_Middle_Name: $Descendant_Middle_Name <br>
Descendant_Surname: $Descendant_Surname <br>
S_SO_First_Name: $S_SO_First_Name <br>
S_SO_Middle_Name: $S_SO_Middle_Name <br>
S_SO_Last_Name: $S_SO_Last_Name <br>
Child1_First_Name: $Child1_First_Name <br>
Child1_Middle_Name: $Child1_Middle_Name <br>
Child1_Last_Name: $Child1_Last_Name <br>
Child2_First_Name: $Child2_First_Name <br>
Child2_Middle_Name: $Child2_Middle_Name <br>
Child2_Last_Name: $Child2_Last_Name <br>
Child3_First_Name: $Child3_First_Name <br>
Child3_Middle_Name: $Child3_Middle_Name <br>
Child3_Last_Name: $Child3_Last_Name <br>
Child4_First_Name: $Child4_First_Name <br>
Child4_Middle_Name: $Child4_Middle_Name <br>
Child4_Last_Name: $Child4_Last_Name <br>
Street: $Street <br>
City: $City <br>
StateProvince: $StateProvince <br>
PostalCode: $PostalCode <br>
Phone: $Phone <br>
Email: $Email <br>
Confirm: $Confirm <br>
Descended From: $immigrant <br>
Adults: $Adults <br>
Children: $Children <br>
RegistrationFee: $RegistrationFee <br>
Comments: $Comments <br>
EOD;
$headers = "From: $email\r\n";
$headers .= "Content-type: text/html\r\n";
/* if we got any errors echo out the error otherwise send the mail */
if($error != "") {
echo $error;
}else{
$success = mail ($webMaster, $emailSubject, $body, $headers);
echo "Your Registration has been submitted successfully. We will contact you by email and confirm your Registration within 48 hours.";
}
}else{
/* If $_POST check is false give this message */
echo "Form Submission error. <a href='javascript:history.back(1);'>Back</a>";
}
?> [/php]