I have a form I'm creating programmatically with a custom module, and I need to add the Google recaptcha to it. In the Google reCaptcha module's settings page (/admin/config/spam_protection/google_recaptcha/forms) I only see the login, register and comments forms and no way to add a custom form (like in the captcha module).

I googled as well as looked in the Google Captcha module's files and API file and can't find any hooks or info on how I can add the captcha element to a custom form. Any pointers would be appreciated!

1 Answer 1


You can use recaptcha module (https://www.drupal.org/project/recaptcha) and in captcha settings(admin/config/people/captcha) you can add your custom form's form_id and select the challenge type reCAPTCHA(from module recaptcha). This should work.

  • Interestingly, the captcha module doesn't work with the form_id if the custom form's function name is different. So if the custom function that creates the form is function foo_form() and the form id is set to bar_form inside the form function, I had to put foo_form in the captcha's settings. May 19, 2017 at 3:27
  • 1
    For those coming here for Drupal 8, I've written a guide here to setting up Captcha for a form (specific focus in the instructions is for making use of the form id, which might not be obvious enough for some): drupal.org/project/captcha/issues/2736881#comment-13594561 May 3, 2020 at 20:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.