How to Add a CAPTCHA Test to Your Feedback Form Script

Reducing Spam in Your Contact Form with ReCAPTCHA


How to Add a CAPTCHA Test to Your Feedback Form Script: Reducing Spam in Your Contact Form

by Christopher Heng, thesitewizard.com

Over the years, I have received many requests from webmasters to add some sort of spam filtering capability to the contact form script generated by the Free Feedback Form Script Wizard. The reason, of course, is that spammers nowadays send automated computer programs, called "spam bots", to scour the web for feedback forms to dump spam into. As such, if your email software or email service doesn't have extensive spam removal facilities, you will probably be inundated by spam submitted through your own contact form.

This article teaches you how you can add a basic spam reducing facility, called the CAPTCHA test, to the feedback form generated by the wizard. You've probably encountered such tests before: after filling in a contact form, you are usually required to enter some string of letters or numbers to prove that you are a human and not a spam bot. If you don't know what I'm talking about, take a look at one such form at the Feedback Form with CAPTCHA Demo page.

More About CAPTCHA Tests

CAPTCHA stands for "Completely Automated Public Turing test to tell Computers and Humans Apart". The idea is to create a test that any human can pass easily but computer programs will fail. It is useful for things like feedback forms since you want humans to be able to send you feedback, but you don't want spam programs to send you its junk.

There are many different types of CAPTCHA tests around. One type, which is the sort we will use here, places a series of words in a graphical image and asks your human visitor to enter the words he/she sees. The hope is that most computer programs won't be able to "see" the words (since programs can't actually "see" anything) and so will be unable to give the correct answer.

Of course this is not foolproof. There are a number of ways to defeat this, such as to incorporate optical character recognition (OCR) technology into the spam bots, or to employ cheap (human) labour to decode it, etc. However, the plan is that having such a test will at least reduce some of the spam entering your mail box by weeding out the less sophisticated spam bots wandering around the Internet.

Who is this article for?

This article is for the ordinary non-technical webmaster, who simply wants to add a CAPTCHA test to their web form. It is NOT for the programmer who wants to learn how to implement their own CAPTCHA test.

If you are a programmer, looking for a way to create your own CAPTCHA test, you may want to check out the following, more relevant, articles:

If you don't want to reinvent the wheel, you may also be interested in checking out the Free PHP CAPTCHA Scripts page to see how others have implemented the CAPTCHA facility for their form. For the curious, I have simply used the ReCAPTCHA script linked to on that page for my form.


Disadvantages of Adding the CAPTCHA Test

Before you rush out to add the CAPTCHA test, note that there are important disadvantages to adding this CAPTCHA test.

If your email server and software have sufficiently good spam filters that have warded off spam in the past, and you think you don't really need the CAPTCHA facility, consider holding off on it. Otherwise, you may be introducing a problematic cure for a non-existent disease. But it's up to you, of course. I just wanted to make sure you have enough information to make an informed decision.

How to Add the CAPTCHA Test to Your Feedback Form

To enable the CAPTCHA option in the feedback form generated by the wizard, do the following.

  1. Sign up with the ReCAPTCHA site

    Go to the ReCAPTCHA website, and sign up for an account. The service is free, or at least it was when I wrote this article. (If it ever stops being free, please let me know and I'll modify the wizard to use a different CAPTCHA facility.) You'll be required to supply a username, password, your email address and your website's domain name.

    When you've finished signing up, you will be given two strings of cryptic letters and numbers. These are your public and private "keys". You will need to enter these keys into the Feedback Form Wizard, so I recommend that you keep the ReCAPTCHA web page open, so that you can just copy and paste the strings. Don't type them manually or you may introduce typing errors and give the wrong keys to the wizard.

  2. Enter Your Keys into the Feedback Form Wizard

    Go to the Free Feedback Form Wizard. Read the instructions and the terms of use and fill in the details requested. (You'll have to choose the PHP script because I haven't got around to implementing the facility in the Perl version.)

    When you reach the "Advanced Options", enter your ReCAPTCHA public and private keys in answer to the question "To enable the CAPTCHA test, please enter both your ReCAPTCHA Public Key and your ReCAPTCHA Private Key". Be sure to enter them into the correct blanks: that is, make sure that your public key goes into the "Public Key" field and your private key goes into the "Private Key" field. These keys have to be integrated into the form and script that is created by the wizard, which is why they are requested. (Don't worry. Like all the other data you enter into the wizard, they are not recorded anywhere, not even in my web logs. As the ReCAPTCHA site so aptly puts it, I'm trying to help you block spam, not introduce it.)

    Follow the rest of the instructions in the wizard to create your feedback form HTML code and feedback form script. Do not close this window.

  3. Obtain the recaptchalib.php file

    Since you enabled the CAPTCHA facility, the feedback form script needs an additional program file provided by the ReCAPTCHA website. (Note: if you did not enter your public and private keys into the wizard, you do NOT need to get this file. This file is only needed if you have enabled the CAPTCHA test.)

    Go to the ReCAPTCHA library site and download the recaptcha-php-1.11.zip file. That is, just click the link labelled "recaptcha-php-1.11.zip" to get the file onto your own computer. Save it anywhere on your computer (eg, your desktop). This applies to you whether you are using Windows, Mac OS X, Linux, or whatever.

    When the file has been successfully downloaded, open the zip file. On Windows XP and above, this is done by simply double-clicking the file. A folder window should open, showing another folder called recaptcha-php-1.11. Double-click that folder as well. You should now see 5 files listed in your window.

    Drag the file named "recaptchalib.php" from the window to the same location where you saved the "feedback.php" file generated by the Feedback Form Wizard. Later, when you publish/upload your feedback.php file, you will need to publish/upload this file as well. It is to be uploaded to the same folder as your feedback.php file. Let me say that again. The recaptchalib.php file is to be placed in the same location as your feedback.php on your website.

    You can ignore all the other files in the zip file. You don't need them. In fact, once you've copied the recaptchalib.php file, you can delete the zip file if you want.

    (Note: if you use Windows, and can't find the "recaptchalib.php" file, it's possible that Windows has hidden a part of the filename [namely, the file extension] from you. Consider configuring Windows to show you the full filename instead of hiding it. As a webmaster, you have to deal with all sorts of files with different extensions that have different behaviour depending on the extension, so it's best not to blind yourself to the true filename.)

  4. Update Your Website

    Do the rest of the stuff mentioned by the feedback form wizard for creating your feedback.php file and inserting your form code into your web page. Then upload (publish) everything (including the feedback.php and recaptchalib.php files) to your site. Detailed instructions for doing this can be found in the usual feedback form tutorials (as well as in the results page of the Feedback Form Wizard):

    Note that those tutorials do not mention the recaptchalib.php file, since they only deal with the main feedback form script. However, as I said above, just copy the file to the same place you saved the feedback.php file, and upload it together with the rest of your website.

    You may also want to modify your "Error" page to help people failing the CAPTCHA test (it happens). See the error page on the Feedback Form with CAPTCHA Demo for an example of the sort of things you can say.

That's it. Once the form is "live" on your website, test your form by sending yourself a message.

Additional Things to Note

Conclusion

The CAPTCHA test is probably one of the most frequently requested feature for my feedback form script, probably because there are so many beleaguered webmasters struggling with spam. Following the steps given in this CAPTCHA guide will allow you to add the test to your web form without having to learn any programming at all.

Copyright © 2009-2013 by Christopher Heng. All rights reserved.
Get more free tips and articles like this, on web design, promotion, revenue and scripting, from http://www.thesitewizard.com/.

thesitewizard™ News Feed (RSS Site Feed)  Subscribe to thesitewizard.com newsfeed

Do you find this article useful? You can learn of new articles and scripts that are published on thesitewizard.com by subscribing to the RSS feed. Simply point your RSS feed reader or a browser that supports RSS feeds at http://www.thesitewizard.com/thesitewizard.xml. You can read more about how to subscribe to RSS site feeds from my RSS FAQ.

Please Do Not Reprint This Article

This article is copyrighted. Please do not reproduce this article in whole or part, in any form, without obtaining my written permission.

Related Pages

New Articles

Popular Articles

How to Link to This Page

It will appear on your page as:

How to Add a CAPTCHA Test to Your Feedback Form Script: Reducing Spam in Your Contact Form





Home
Donate
Contact Us
Link to Us
Topics
Site Map

Getting Started
Web Design
Search Engines
Revenue Making
Domains
Web Hosting
Blogging
JavaScripts
PHP
Perl / CGI
HTML
CSS
.htaccess / Apache
Newsletters
General
Seasonal
Reviews
FAQs
Wizards

 

 
Free webmasters and programmers resources, scripts and tutorials
 
HowtoHaven.com: Free How-To Guides
 
Site Design Tips at thesitewizard.com
Find this site useful?
Please link to us.