Skip to main content

How to Protect Your Drupal Site from Spam with Google reCAPTCHA

Spam is a common problem for website owners, especially if your site has forms for user registrations, comments, or contact submissions. Fortunately, Google reCAPTCHA can help prevent automated spam submissions. In this guide, we’ll show you how to easily add reCAPTCHA to your Drupal site. 

Why Use reCAPTCHA on Your Drupal Site?

  • Blocks spam bots from submitting forms
  • Protects user data and improves security
  • Enhances user experience with minimal interaction (especially reCAPTCHA v3)
  • Free and easy to integrate

Steps to Add Google reCAPTCHA to Drupal

 

1.Install Required Modules

Use Composer to install

composer require drupal/captcha drupal/recaptcha

Then enable the modules with Drush

drush en captcha recaptcha -y

or via Admin UI → Extend → Enable CAPTCHA and reCAPTCHA

 

2.Register and Retrieve reCAPTCHA Keys

Visit the Google admin console to register your site and obtain:

  • Site Key
  • Secret Key
Image
loading reCAPTCHA

 

Choose either reCAPTCHA v2 (checkbox/invisible) or v3.
These keys are essential and should be kept confidential.

  • This is the Google reCAPTCHA v2 Checkbox settings page.
  • You can enter your site label, domain name, and email of the owner.
  • Adjust the security level using the slider.
  • Make sure to check both boxes for verification and alerts, then click Save.
     
Image
reCAPTCHA Setting
  • This page shows your Google reCAPTCHA keys.
  • The Site Key is used in your website’s frontend code.
  • The Secret Key is used on the server to verify responses.
  • Copy and use them for client-side and server-side integration.
     
Image
Google reCAPTCHA keys

 

3.Configure reCAPTCHA in Drupal

Configuration → People → CAPTCHA settings
  • Select reCAPTCHA for default challenge type
  • Navigate to the reCAPTCHA tab, and enter your Site Key and Secret Key
  • Choose reCAPTCHA version, theme, and size as needed
  • Save the configuration
     

CAPTCHA Configuration

Image
CAPTCHA CONFIGURE

reCAPTCHA v3 settings

Image
reCAPTCHA v3 setting

4.Enable reCAPTCHA on Specific Forms

Within CAPTCHA settings, switch to Form Settings:

  • Select forms like login (user_login_form), registration (user_register_form), or Webforms
  • Set reCAPTCHA as the challenge type
  • Save settings

 

5.(Optional) Add reCAPTCHA to Webform Module

If you're using Webform

  • Enable Webform CAPTCHA/Anti-Spam
  • Add a CAPTCHA element and select reCAPTCHA
  • Save the form to apply protection
     
Haris Khan

Haris Khan

Drupal Frontend developer

Add new comment