wright67uk Posted February 23, 2012 Share Posted February 23, 2012 I have a basic question for anyone that can help me. Ive added a captcha input field to the form below, as Im having problems with spam appearing on my testimonial page. 1) How can I prevent the form from being sent if the wrong or no answer is in the form field. 2) How can i have a message appear saying "Sorry wrong answer" if the from isnt sent for the above reason? add.php <form method="post" action="process2.php" > <textarea rows="25" cols="100" wrap="physical" name="data"> </textarea> <input type="hidden" name="area" value="testimonial"/> What is 5+5? <input type="text" name="captcha"/> <input type="submit" value="Add "> </form> process2.php <p class="add">Thankyou for submitting your testimonial;</br> <?php $data="<br><br>" . $_POST["data"]; ?><br /> <?php $area=$_POST["area"]; ?> <?php echo $data; ?></p> <?php mysql_query("UPDATE wheelchairwizard SET data = CONCAT(data, '$data') WHERE area = '$area'"); ?> </br> Return to the testimonial page - <a href="http://www.wheelchairwizard.co.uk/testimonials.php">click here</a> Quote Link to comment https://forums.phpfreaks.com/topic/257648-adding-a-captcha-to-a-basic-form/ Share on other sites More sharing options...
smerny Posted February 23, 2012 Share Posted February 23, 2012 if($_POST['captcha'] == 10){ //output like you have now } else { //telll them they entered the wrong thing } thats not a very secure captcha though, if you want something more secure, google "php captcha tutorial" or something Quote Link to comment https://forums.phpfreaks.com/topic/257648-adding-a-captcha-to-a-basic-form/#findComment-1320556 Share on other sites More sharing options...
BigTime Posted February 23, 2012 Share Posted February 23, 2012 following up on smearny... Google around for math captcha and you will find a full code that randomizes that process into numbers and text. I haven't gotten a single piece of spam on a form I implemented with that in 3 years. Theres also a nifty picture puzzle captcha that works quite well also and is probably easier to implement called key captcha . Quote Link to comment https://forums.phpfreaks.com/topic/257648-adding-a-captcha-to-a-basic-form/#findComment-1320563 Share on other sites More sharing options...
Zane Posted February 23, 2012 Share Posted February 23, 2012 I'm not going to tell you to give up on making your CAPTCHA system, but I will suggest that you make use of a system that's already stable... and FREE http://www.google.com/recaptcha If you're looking for a not-so-difficult version, then check these out http://woork.blogspot.com/2009/02/10-free-captcha-scripts-and-services.html To put it short, there's no point re-inventing the wheel unless that wheel is revolutionary. Quote Link to comment https://forums.phpfreaks.com/topic/257648-adding-a-captcha-to-a-basic-form/#findComment-1320582 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.