Good morning. Below is how my php formmail script processes my spam question. Whats the simplest way to write the same type of thing but only checking for if “name, phone, and email” inputs are NOT left empty? Thanks
html required - doesn’t get any easier than that does it. But to keep with my jquery validation styling and php validation already in place its got to be php as the back up validation.
What you do after checking the REQUEST METHOD you trim the POST array all at once, then you check if the particular fields are empty, If they are, you put the errors in an error array. Just past that, you check the errors array and if it is not empty, you loop over each of the errors and output them to the user.
$error = [];
if ($_SERVER['REQUEST_METHOD'] == 'POST')
{
// Trim POST array here....
if (empty($_POST['name']))
{
$error['name'] = 'Name Required.';
}
if (empty($_POST['phone']))
{
$error['phone'] = 'Phone Required.';
}
if ($error)
{
// Handle errors
}
else{
//Processs Form
}
}