I've made it so I have 1 form which includes a hidden div with extra input fields that are displayed when the "Add More" button is clicked. When the form is submitted with invalid data, the Quote Form is re-displayed holding the valid data, as well as, error messages for the invalid data.
The problem is, the original 3 fields that are shown when you first get to the page are re-displayed above the Quote Form when error handling.
Is there a way to hide those 3 fields when the Quote Form is re-displayed with errors?
// Error checking. If there are errors, call the redisplayForm function to redisplay the Quote Form Handler.
if ($errorCount>0 || $errorCount<0) {
redisplayForm($bizName, $bizType, $address1, $address2, $city,
$state, $zip, $sqft, $cName, $email, $bizNameErr, $bizTypeErr,
$address1Err, $cityErr, $stateErr, $zipErr, $sqftErr, $cNameErr, $emailErr );
$bizNameErr = $bizTypeErr = $address1Err = $address2Err = $cityErr = $stateErr
= $zipErr = $sqftErr = $cNameErr = $emailErr = "";
$bizName = $bizType = $address1 = $address2 = $city = $state
= $zip = $sqft = $cName = $email = "";
// If there are no errors, an email will be sent to Conversion Worx with the user's input.
} else {
$To = "myemail";
$Subject = "Quote Form Results";
$Message = "Business Name: " . $bizName . "\n"
. "Business Type: " . $bizType . "\n"
. "Address Line 1: " . $address1 . "\n"
. "Address Line 2: " . $address2 . "\n"
. "City: " . $city . "\n"
. "State: " . $state . "\n"
. "Zip Code: " . $zip . "\n"
. "Estimated Square Feet: " . $sqft . "\n"
. "Contact Name: " . $cName . "\n"
. "Email Address: " . $email;
$result = mail($To, $Subject, $Message);
}
// If email to Conversion Worx is sent succesfully, send thank you email to user.
if (isset($result)) {
$To = $email;
$Subject = "Virtual Tour Quote Request";
$Headers = 'From: myemail' . "\r\n" .
'Reply-To: myemail' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
$Message = $cName . ",";
$Message .= "\n" . "\n" . "Thank you for your interest in our 3D 360° Virtual Tours!";
$Message .= "\n" . "\n" . "Your information has been submitted. ";
$Message .= "A Conversion Worx represenative will be contacting you shortly to arrange a quote via phone or on-site visit.";
$Message .= "\n" . "\n" . "We look forward to working with you! ";
$Message .= "\n" . "\n" . "\n" . "Sincerely,";
$Message .= "\n" . "\n" . "The Conversion Worx Team";
$result = mail($To, $Subject, $Message, $Headers);
}
?>
<?php
$errorCount = "";
$bizNameErr = $bizTypeErr = $address1Err = $address2Err = $cityErr = $stateErr
= $zipErr = $sqftErr = $cNameErr = $emailErr = "";
$bizName = $bizType = $address1 = $address2 = $city = $state
= $zip = $sqft = $cName = $email = "";
// Check to make sure the required fields from the Quote Form are not empty
if ($_SERVER["REQUEST_METHOD"] == "POST") {
if (empty($_POST["bizName"])) {
$bizNameErr = "Business name is required";
++$errorCount;
} else {
$bizName = test_input($_POST["bizName"]);
}
if (empty($_POST["cName"])) {
$cNameErr = "Contact Name is required";
++$errorCount;
} else {
$cName = test_input($_POST["cName"]);
}
if (empty($_POST["email"])) {
$emailErr = "Email is required";
++$errorCount;
} else {
$email = test_input($_POST["email"]);
}
if (empty($_POST["bizType"])) {
$bizTypeErr = "Business Type is required";
++$errorCount;
} else {
$bizType = test_input($_POST["bizType"]);
}
if (empty($_POST["address1"])) {
$address1Err = "Address Line 1 is required";
++$errorCount;
} else {
$address1 = test_input($_POST["address1"]);
}
if (!empty($_POST["address2"])) {
$address2 = test_input($_POST["address2"]);
}
if (empty($_POST["city"])) {
$cityErr = "City is required";
++$errorCount;
} else {
$city = test_input($_POST["city"]);
}
if (empty($_POST["state"])) {
$stateErr = "State is required";
++$errorCount;
} else {
$state = test_input($_POST["state"]);
}
if (empty($_POST["zip"])) {
$zipErr = "Zip Code is required";
++$errorCount;
} else {
$zip = test_input($_POST["zip"]);
}
if (empty($_POST["sqft"])) {
$sqftErr = "Square Feet is required";
++$errorCount;
} else {
$sqft = test_input($_POST["sqft"]);
}
}
// Form validation
function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}