I\'ve scoured the entire internet trying to find a solution to what I\'m missing here (or doing wrong). My form doesn\'t validate even when the check box is checked. Everything
The problem with your current validation is that you're using if-else
wrongly and that you're using exit
on every statement which will terminate your script prematurely.
You can do this instead:
For Terms:
//set an error counter to trigger the `exit`
$error_counter = 0;
if(trim($name) == '') {
echo '
';
$error_counter++;
}
if(trim($email) == '') {
echo ' ';
$error_counter++;
}
if(!isEmail($email)) {
echo ' ';
$error_counter++;
}
if(trim($subject) == '') {
echo ' ';
$error_counter++;
}
if(trim($comments) == '') {
echo ' ';
$error_counter++;
}
if(empty($terms)) {
echo ' ';
$error_counter++;
}
//if `$error_counter > 0 > 0` it will trigger the `exit()` to stop the script and display the errors.
if($error_counter > 0){
exit();
}
There's a more beautiful approach to do this. Feel free to add suggestions for the OP.