I'm using the webform module as a block. I've got CAPTCHA enabled and set to use reCAPTCHA. The web form is being submitted via AJAX. Since there is no D7 AJAX module, I had to code my own using http://drupal.org/node/1211320#comment-4954050. The first time the form loads, it works perfectly. Once the user submits the form, although the validation is correct, the reCAPTCHA widget is not rerendered. The only thing that is left is the "This question is for testing…" message. I assumed it had something to do with the inline JS not firing after the AJAX callback because both the math and image CAPTCHAs work using this method.

As an interim solution I copy and pasted the "Recapatcha.create…" JS code into a custom module using Drupal.behaviors… to trigger it after the AJAX response.

Here's a sample:

(function ($) {

  Drupal.behaviors.MY_MODULE = {
    attach: function (context, settings) {
  
      Recaptcha.create('reCAPTCH_PUBLIC_KEY', 'recaptcha_ajax_api_container', {theme: 'clean'});
    }
  };
})(jQuery);

Is there a way to permanently move this to a separate js file within the module. Maybe it checks Drupal.settings to see if the user is using the AJAX API for reCAPTCHA then instantiates it.

Thanks
- H

Comments

liam morland’s picture

Version: 7.x-1.7 » 7.x-1.x-dev
Status: Needs review » Active

I don't know if that would work or not. If you can get it working, please post your patch and then set the issue to Needs Review.

liam morland’s picture

Status: Active » Fixed

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.