I have a question about the home page e-mail submission box for my website. When you interact and get to the second form, the script does not output an error message if the name field is left empty.
The script:
<?php
$instance = new CheckForm;
$instance -> checkSubmission();
class CheckForm
{
public function checkSubmission()
{
$response = array("validation" => " ", "message" => " ", "database" => " ");
if ($_POST['country'] != "Select Country")
{
if (!is_null($_POST['confirmEmail']) && !is_null($_POST['name']))
{
$origEmail = $_POST['origEmail'];
$confirmEmail = $_POST['confirmEmail'];
if ($origEmail == $confirmEmail)
{
$name = htmlspecialchars($_POST['name']);
$ageRange = $_POST['age'];
$country = $_POST['country'];
require_once("categoryfinder.php");
$categoryFinder = new CategoryFinder;
$category = $categoryFinder -> getCategory();
$response = array("validation" => "pass", "message" => "Thanks for joining the e-mail list, <b>" . $name . "</b>, under the e-mail address, <b>" . $confirmEmail . "</b>.", "database" => "pass");
try{
require_once('databasewriter.php');
$dbWriter = new DatabaseWriter;
$dbWriter -> writeUserToDatabase($confirmEmail, $name, $ageRange, $country, $category);
} catch (PDOException $e) {
$response = array("validation" => "pass", "message" => "Thanks for joining the e-mail list, <b>" . $name . "</b>, under the e-mail address, <b>" . $confirmEmail . "</b>.", "database" => "fail");
}
} else {
$response = array("validation" => "fail", "message" => "E-mail addresses don't match.", "database" => "fail");
}
} else {
if (is_null($_POST['confirmemail'])){
$response = array("validation" => "fail", "message" => "Confirmation e-mail not entered.");
} elseif (is_null($_POST['name'])) {
$response = array("validation" => "fail", "message" => "Please enter a name.");
}
}
} else {
$response = array("validation" => "fail", "message" => "Please select a country.");
}
echo json_encode($response);
}
}
?>
What seems to be the issue? :cap:
But it’s still not posting that particular error to the #errormessage <p> element, whereas if I don’t select a country it says “Please select a country” like it should.
I think it may be due to the nested if statement near the end of the script.