Help with Contact Form checkbox

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);
}
?>

Hi

use javascript validation for checkbox is checked or not. if checked means show alert message else allow to submit form.

This part is the wrong way around. It’s preventing the form from submitting IF the checkbox was checked.


if(isset($_POST['agree']))
{  
echo "If you agree with the terms, check the Agree check box";  
$continue = false;
}

That should be if(!isset()) to stop the submission when not checked.

Also:


$mailbody .= date('Y-m-d H:i:s',strtotime("now"));  //strtotime not necessary
$mailbody .= date('Y-m-d H:i:s'); //same thing