Someone had helped me set up a basic Contact Form that simply sends the info to an email address upon submission. Additionally, I got help to add the functionality of a CAPTCHA, and a function to Agree To Terms. Well, instead of Captcha, a simple question is posed in the Form: Is Fire Hot or Cold? Anyway, I plugged in the suggested lines of code into the html form, and the accompanying very simple php handler (below). After answering the question (wrong), the user exits to a blank page that simply says "wrong answer". I'd like to have the words "Wrong Answer" appear on the Contact Form page, instead of exiting. And I'd like to add a link to the Agree To Terms, so the user can read the terms they are agreeing to, and also not allow a user to submit/proceed until he agrees. I'm sure these are very simple tweaks. Please let me know if you're interested in helping me "have the words "Wrong Answer" appear on the Contact Form page, instead of exiting" and "add a link to the Agree To Terms, so the user can read the terms they are agreeing to, etc.". Thanks <?php $mailto = 'email@email.com'; $mailsubj = "Contact Form submission"; $mailhead = "From:CForm\n"; $mailbody = "--- Contact form results ---\n"; foreach($_REQUEST as $key => $value) { if($key != 'PHPSESSID') { $mailbody .= $key.": ".$value."\n"; } } if(isset($_POST['ans']) && $_POST['ans']!='hot') exit('Wrong answer'); if(empty($_POST['agree']) || $_POST['agree'] != 'agree') { echo "If you agree with the terms, check the Agree check box"; exit; } $mailbody .= date('Y-m-d H:i:s',strtotime("now")); mail($mailto, $mailsubj, $mailbody, $mailhead); echo "<h2>Thanks!</h2>" //print_r($_REQUEST); ?> Code (markup):
try this.. <?php $mailto = 'email@email.com'; $mailsubj = "Contact Form submission"; $mailhead = "From:CForm\n"; $mailbody = "--- Contact form results ---\n"; foreach($_REQUEST as $key => $value) { if($key != 'PHPSESSID') { $mailbody .= $key.": ".$value."\n"; } } $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); } ?> PHP:
Thanks for the code, however, upon testing, I am able to proceed/submit even if the Agree To Terms checkbox is unchecked. Can you help me remedy this? I'd like it so the user is unable to proceed unless the heckbox is checked. Thanks again