Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Hi, guys.
I had a ajax link, on click I insert form in html. In this form I have reCAPTCHA field, reCAPTCHA doesn't shown in this case.
There are anonymized html:
<div class="captcha">
<input type="hidden" name="captcha_sid" value="11111">
<input type="hidden" name="captcha_token" value="11111">
<input type="hidden" name="captcha_response" value="Google no captcha">
<div class="g-recaptcha" data-sitekey="111111111111111" data-theme="light" data-type="image" data-tabindex="2"></div>
</div>
As I see in recaptcha_captcha drupal_add_html_head is used and it's not working for ajax.
I add checking if it's ajax call, and in this case use drupal_add_js instead of drupal_add_html_head, it's work for me.
Could you please check the patch.
Comment | File | Size | Author |
---|---|---|---|
#17 | recaptcha-ajax-support-2875698-17.patch | 5.73 KB | Steven Jones |
| |||
#12 | recaptcha-ajax-support-2875698-11.patch | 1.3 KB | Joao Sausen |
#6 | recaptcha_2875698__allow_recaptcha_with_ajax.patch | 1.29 KB | trebormc |
|
Comments
Comment #2
hass CreditAttribution: hass commentedComment #3
voron CreditAttribution: voron at Internetdevels commentedComment #4
voron CreditAttribution: voron at Internetdevels commentedUnfortunately my path dosen't work in case if user close popup with form and open it again. I'll try to work around.
Comment #5
trebormcthis patch work correctly with the module Asaf in D7
https://www.drupal.org/project/asaf
Thanks
Edit: My error, only works on first ajax load
Comment #6
trebormcnew patch to reload recaptcha in all ajax calls
Comment #7
mattjones86This shouldn't have been marked as a duplicate, since the referenced parent issue is for the 8.x branch. If someone can find a duplicate 7.x issue and link it here then feel free to close again.
What I would say about the patch is that it still throws an 'Undefined method' error on first page load. It should also be checking for the existence of grecaptcha.render in case everything has not fully initialised at the time of load.
It works great for ajax requests though.
Comment #8
greggles@mattjones86: it's common to fix issues in one branch and then mark the issue as needs porting to the other branch, which I guess is what hass was doing. If this is going to be open separately, it seems worthwhile to make it really clear from the title that it's 90% the same, just for a different branch.
Comment #9
TwoDFYI: There's also a patch for this in #2493183-153: Ajax support / Use behaviors which works well.
It's also using
#attached
which is preferred over callingdrupal_add_js()
.Comment #10
Joao Sausen CreditAttribution: Joao Sausen at Dexa commented#6 worked well hereComment #11
Joao Sausen CreditAttribution: Joao Sausen at Dexa commenteddeleted
Comment #12
Joao Sausen CreditAttribution: Joao Sausen at Dexa commentedComment #13
dench0 CreditAttribution: dench0 commentedHere the fixed patch from #12 to apply it within the module directory.
Comment #14
Fabsgugu CreditAttribution: Fabsgugu commentedPatch #13 work for me.
Comment #15
Steven Jones CreditAttribution: Steven Jones at ComputerMinds commentedI'm going to mark this back as needing review, and take a patch from the corresponding D8 issue to move this one along, specifically I'm working from #2493183-168: Ajax support / Use behaviors.
I've fixed the broken test from that patch, and put back the defer attribute on the script that that patch removed, the only other real change is that the tag is going to lose the async attribute, but I've included support for that once #1664602: Allow attributes to be passed to drupal_add_[css|js] (SRI) lands.
This patch is superior to the one in #13 here because:
Comment #17
Steven Jones CreditAttribution: Steven Jones at ComputerMinds commentedDoh! Copy/paste fail there.
Comment #18
torotil CreditAttribution: torotil at more onion commentedI’ve had a look at the code and think that the overall approach looks good. There are a few code-style issues there though. Although the existing recaptcha isn’t exactly coding-style compliant at least new code should be.
I’m also marking the core issue as related.
Comment #19
james.williams CreditAttribution: james.williams at ComputerMinds commentedCould you be more specific about what the code style issues that you're referring to are please?
Comment #20
torotil CreditAttribution: torotil at more onion commentedSorry, for the vague comment. Here are is the relevant output of phpcs (based on the current 7.x-2.x):
For the commented out lines I would either ignore it or use
/* … */
to silence phpcs.