Chrisj Posted August 16, 2011 Share Posted August 16, 2011 Someone had helped me set up a basic Contact Form that simply sends the info to an email address upon submission, and helped 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); ?> Quote Link to comment https://forums.phpfreaks.com/topic/244883-contact-form-tweaks/ Share on other sites More sharing options...
phpSensei Posted August 16, 2011 Share Posted August 16, 2011 If your question is always "Is Fire Hot or Cold" then by-passing this 'anti-spamming' system if you so call it won't be very hard. If you would like to have the errors display on top of the contact form, you will need to leave the form's action to empty, to it sends the HTTP POST vars to itself. example <?php if(isset($_POST['Submit'])){ $answer = trim(strtolower($_POST['answer'])); if(empty($username)){ print "Please enter your username"; }elseif($answer != "hot"){ print "Wrong Answer!"; }else{ header("location:somepage.php"); exit(); } } ?> <form method="Post" action=""> <input type="text" name="answer" id="answer" /> <input type="Submit" name="Submit" value="Submit" /> </form> Quote Link to comment https://forums.phpfreaks.com/topic/244883-contact-form-tweaks/#findComment-1257963 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.