Do you use DevPortal with the bootstrap modal forms? Want to enable recaptcha for user registration AND login?

Do you like recaptcha? Want to enable it in your Drupal-based developer portal for both user registration and user login, WITH the modal bootstrap forms?

There’s been a longstanding bug in the Drupal recaptcha module that obstructs your joy. Happily, 6 days ago, a kind user in the Drupal community posted this patch:

https://www.drupal.org/files/issues/recaptcha-multiple-per-page-reroll-1833822-59.patch

…which eliminates the problem!

Try it out!

For those of you who are not all caught up yet.... What is ReCaptcha, you might ask?

ReCaptcha is Google's implementation of a user-friendly CAPTCHA. We all know what Captcha looks like:

2579-captcha-1.png

or

2580-captcha-2.png

CAPTCHA, I have come to learn, refers to "Completely Automated Public Turing Test To Tell Computers and Humans Apart", and the term CAPTCHA is trademarked by my alma mater, Carnegie Mellon University.

The way Google implements their Captcha (known as ReCaptcha) requires including a well-known Javascript module in the browser page (https://www.google.com/recaptcha/api.js). According to the doc by Google, by default that Javascript then scans the page for a form that contains a captcha placeholder element, and then inserts the Captcha iframe into the page in the appropriate spot. The recaptcha module for Drupal is just a Drupal wrapper around that simple mechanism.

The problem is that Google's JS by default only inserts a (re)captcha element in the first placeholder it finds. If you have Drupal, with the bootstrap modal forms enabled, there is one form for user registration, and one form for user login. The Google recaptcha library inserts the captcha widget only into the login form. (sad trombone)

But Google's recaptcha library is not really at fault here. The Google library was designed to solve the "add recaptcha to a single form" case, probably the 80% case, very simply. The Drupal module wasn't designed to be general enough to handle multiple modal forms. With the patch I referenced above, the Drupal module now works. Basically the Drupal module is just being smarter about how it uses the Google recaptcha JS.

Google allows an "explicit" rendering mode (See the doc link I provided above) which is appropriate when there is more than one form, and hence more than one placeholder for a captcha widget. The change is only about 10 lines of code in the recaptcha module. Whew!

The unfortunate truth though, is that this low-risk patch has not yet been accepted into the master recaptcha source.

For now, to get this goodness, you need to apply the patch yourself. To do so, I suggest you download and unpack the latest recaptcha module, into your sites/all/modules/contrib directory. Then apply the diff. (yes, I did it in emacs, so it was easy) Do a git push, and then Verify the recaptcha works on your dev server.

The result is that now you can see recaptchas in both the user login and user registration forms.

2581-register-user.png

2582-login-user.png

Comments
williamking
New Member

How do you activate the module added to sites/all/modules/contrib, and not the module included in the apigee profile (profiles/apigee/modules/contrib)?

anilsr
Staff

@williamking , Just navigate to "admin/modules" page and enable the module. All the modules available in portal are listed in "admin/modules" page.

williamking
New Member

So it should list both modules for activation, and you'll know which one is the modified version and which one is the Apigee profile version? I didn't see that but I might have missed it.

anilsr
Staff

@williamking , You mean same module ?

Drupal / Apigee Developer Portal follows below priority , Find more about same here. Rebuild Registry / Clear All Drupal caches to see changes. So , modules overriden in sites/all/modules/ will have higher priority than in apigee profile. So module in sites/all/modules will be activated. You only see one module in "admin/modules" based on below order.

  1. sites/$SITENAME/modules
  2. sites/all/modules
  3. profiles/$INSTALLPROFILE/modules
  4. modules
natalkaharding
New Member

Thank you so much for posting that Dino! It helped point me to a working patch for a related issue troubling me. In my case I had ajaxified the modals but the recaptcha form was not rendering when the form was returned with user validation errors.

For those who may be having problems with ajaxifying the modals + recaptcha, if the patch that Dino kindly provided does not work for you, there is a newer patch out that might do the trick:

https://www.drupal.org/files/issues/2018-05-07/1833822-143-allow-multiple-per-page-D7.patch

If you'd like to follow the recaptcha drupal module issue queue for this bug, in case newer patches are released, you may do so here:

https://www.drupal.org/node/1833822

Version history
Last update:
‎04-27-2016 06:03 PM
Updated by: