Applies to the pro version
diyform supports Google reCAPTCHA v2, which shows an "I'm not a robot" checkbox on your form. To show the CAPTCHA on your form you need to add some code to your form page and configure the script (diyform.php) to process the CAPTCHA.
reCAPTCHA keys
You will need a "site key" and a "secret key" from Google, so you need a Google account to get them. The Google ReCAPTCHA admin page is here - You need to add your website domain in the settings to get the keys: Click on the settings icon. Click on "+ Add a domain, e.g. example.com" to add your domain. You can then see your site key and secret key under "reCAPTCHA keys".
Add code to your form page
Step 1. Put this line of code on your form page on your website:
It might be marginally quicker if you put it somewhere between <head> and </head>, but you can also put it anywhere between <body> and </body>.
Step 2. Put this line of code on your form (somewhere between <form...> and </form>) where you would like the "I'm not a robot" checkbox to appear:
Replace xxxxxxxxxxxxxxxxxxxxx with the site key you got from Google.
Configure the script
Open the script (diyform.php) in a text editor. Locate this line:
Change the 0 to 1, like so:
Locate this line:
Enter the secret key you got from Google, like this example (using a fictitious key):
Upload the files
Upload your form page and the script to your webspace (remembering to save the files first!). Put them in the same directory (folder).
That's it, done. Your form will now display the reCAPTCHA "I'm not a robot" checkbox. When a visitor submits the form, the script checks if the checkbox has been checked, if not it will issue an error and won't send an email to you.
© copyright diyform 2025