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.
Comments
Comment #2
hass commentedComment #3
voron commentedComment #4
voron 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
#attachedwhich is preferred over callingdrupal_add_js().Comment #10
joao sausen commented#6 worked well hereComment #11
joao sausen commenteddeleted
Comment #12
joao sausen commentedComment #13
dench0Here the fixed patch from #12 to apply it within the module directory.
Comment #14
fabsgugu commentedPatch #13 work for me.
Comment #15
steven jones 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 commentedDoh! Copy/paste fail there.
Comment #18
torotil 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.williamsCould you be more specific about what the code style issues that you're referring to are please?
Comment #20
torotil 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.Comment #21
jkingsnorth commentedThe patch in #15 does not work for me.
In my use-case we have recaptcha set up as a fallback for recaptcha_v3.
When we fallback to the 'I'm not a robot' checkbox, we tick the box and then we get the loading spinner in the element, but it doesn't verify us.
The patch in #13 does work OK in our use-case.
Comment #22
liam morlandDrupal 7 is no longer supported. If this applies to Drupal 10/11, please re-open.