3

I need to add a reCaptcha to my form; creating the form then adding the form ID to the reCaptcha settings did nothing.

1 Answer 1

9

I added the following form item to my form.

$form['captcha'] = array(
  '#type' => 'captcha',
  '#captcha_type' => 'recaptcha/reCAPTCHA',
);

It's pretty simple but it may trip some others up so hopefully this post saves someone time.

If you want to use some other captcha method you have installed on your site you can easily replace #captcha_type by going to /admin/config/people/captcha and using a tool like Firebug (or just view the page source and do some hunting) to view the options for the "Default challenge type" field on the captcha admin settings page. The values of each option is a valid option for the #captcha_type.

1
  • works for drupal 9 too
    – boroboris
    Commented Feb 16, 2021 at 11:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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