I've been experiencing a problem where the CAPTCHA on a form disappears after an ajax submission is triggered for the form by an addressfield widget. I select a new country, there's an ajax submission to update the addressfield fields for that country, and the CAPTCHA test disappears.
I've traced the cause of this to the fact that the captcha element's #process callback is getting called twice during the ajax submission (probably indicating that the form is getting rebuilt twice as well) and so what happens is this: The javascript settings added inside recaptcha_captca()
get added twice, and they get merged by Drupal with array_merge_recursive()
inside ajax_render()
. That results in Drupal.settings.recaptcha
containing this:
{
theme: ["clean", "clean"],
lang: ["en", "en"],
public_key: ["....", "...."]
container: ["recaptcha_ajax_api_container", "recaptcha_ajax_api_container"]
}
... instead of this:
{
theme: "clean",
lang: "en",
public_key: "....",
container: "recaptcha_ajax_api_container"
}
Obviously this breaks things. I have resolved this by using a static variable to ensure that the drupal_add_js()
calls only happen once per captcha session per request. I'll provide a patch for this.
Comment | File | Size | Author |
---|---|---|---|
#1 | recaptcha-js-once-2231999-1.patch | 1.85 KB | jamesharv |
Comments
Comment #1
jamesharv CreditAttribution: jamesharv commentedPatch attached
Comment #2
Liam MorlandThanks for the patch. This seems to make sense, but I don't understand the source of the $session_id. The documentation for hook_captcha() doesn't state that a number like that is sent as the last argument. Is it really needed? What about just having a static variable that is set to true to first time through and, if it is true, don't put in the JS again?
This requires a re-roll due to #2232701: Use proper function signature for recaptcha_captcha().
Comment #3
Liam MorlandComment #4
myat CreditAttribution: myat commentedI am also facing same problem in reCapture 7.x-2.0.
The problem I have is after ajax form submission, capture is disappearing whether I put correct answer or wrong answer on captcha. Seems like reCaptcha didn't render again after AJAX form submit.
Comment #5
Liam MorlandLet's get this solved in 2.x first, then we can see if the fix will backport.
Comment #6
hass CreditAttribution: hass commentedThere is already a case open, but it requires a totally different solution. Feel free to close if 1.x do not get maintained any longer.
Comment #7
artfulrobot CreditAttribution: artfulrobot as a volunteer commentedIs there any progress on this? I've got this problem with 7.x-2.1.
Comment #8
Liam MorlandThis issue is about 7.x-1.x. As hass said in #6, there is another issue for 7.x-2.x.
Comment #9
hass CreditAttribution: hass commentedComment #10
madelyncruz CreditAttribution: madelyncruz commentedI'm also having this error with 7.x-2.x-dev
Comment #11
Liam MorlandSee comment #6.