• Spam
Search »

Adding a CAPTCHA to your form

Okay! Now let's add the CAPTCHA.

1. At the top of your form page, add the following PHP:

You need to include a valid path from your form page to the API.class.php file. This can be an absolute or relative path (but not a URL!).

2. At an appropriate spot in your form (usually the bottom, but before the form submit button, add this line of PHP to add the CAPTCHA:

3. Include a hidden field in your form that contains the full URL of the form page. This is optional, but may be required depending on your server. Try it without it.

4. Add this code to the top of your form. In the event of the user incorrectly entering CAPTCHA it displays the error.

So far so good! Here's a sample form that should give you an idea of what your form should look like at this point.

Now try loading up the form in your browser and putting through a couple of submissions to confirm that the CAPTCHA is working as expected. You may notice that when you fail to check the field it incorrectly, you're returned to the form page but (a) your field values are all lost and (b) the error message is displayed but doesn't look the way you want, or contains some text you don't like. Both these issues are addressed in the next two steps.