I was provided this code for a Contact Form where the Agree To Terms have to checked in a checkbox in order to submit.
However, I tested and can proceed without checking the box.
Can you help me figure out how to make it mandatory to check the box in order to submit?
Thanks
<?php
$mailto = 'email@email.com';
$mailsubj = "Contact Form submission";$mailhead = "From:CForm\
";
$mailbody = "--- Contact form results ---\
";
foreach($_REQUEST as $key => $value)
{
if($key != 'PHPSESSID')
{
$mailbody .= $key.": ".$value."\
";
}
}
$continue = true;if(isset($_POST['ans']) && $_POST['ans']!='hot')
{
echo 'Wrong answer!';
$continue = false;
}
// if the check box is not checked it will not appear in the $_POST values, it's better to use isset rather than empty
if(isset($_POST['agree']))
{
echo "If you agree with the terms, check the Agree check box";
$continue = false;
}
if($continue)
{
$mailbody .= date('Y-m-d H:i:s',strtotime("now"));
mail($mailto, $mailsubj, $mailbody, $mailhead);
echo "<h2>Thanks!</h2>";
//print_r($_REQUEST);
}
?>