Problem/Motivation

When using ajax callbacks to bring recaptcha elements into the page, or remove them, the recaptcha elements do not work. Using behaviors could resolve that.

Steps to reproduce

Proposed resolution

Defers activation of recaptcha widgets to the behavior, either rendering or resetting as appropriate.

Remaining tasks

Fix multilingual issue reported in comment #314

User interface changes

None, other than making it work!

API changes

None, depending on what is considered the surface API of this module.

Data model changes

None

CommentFileSizeAuthor
#319 recaptcha-MR24-2493183-319.diff25.15 KBanybody
#313 recaptcha-2493183-313-ajax-support.patch24.05 KBryan-l-robinson
#290 recaptcha-ajax-support-2493183-290.patch24.05 KBs_bhandari
#288 recaptcha-ajax-support-2493183-288.patch24.06 KBs_bhandari
#287 recaptcha-ajax-support-2493183-287.patch24.05 KBs_bhandari
#273 recaptcha-ajax-support-2493183-273.patch24.05 KBslasher13
#268 2493183-258-MR9.interdiff.txt2.52 KBneclimdul
#268 2493183-228-258.interdiff.txt6.22 KBneclimdul
#258 recaptcha-ajax-support-2493183-258.patch24.36 KBnileema19
#257 recaptcha-ajax-support-2493183-257.patch24.28 KBnileema19
#256 recaptcha-ajax-support-2493183-255.patch24.34 KBnileema19
#251 recaptcha-ajax-support-2493183-251.patch24.28 KBslasher13
#248 recaptcha-ajax-support-2493183-248.patch28.75 KBzhelmet
#236 resolve-reCAPTCHA-issue.png144.23 KBnpcoder
#228 recaptcha-ajax-support-2493183-228--interdiff.patch841 bytesjedihe
#228 recaptcha-ajax-support-2493183-228.patch28.77 KBjedihe
#227 recaptcha-ajax-support-2493183-227--interdiff.patch664 bytesjedihe
#227 recaptcha-ajax-support-2493183-227.patch28.74 KBjedihe
#226 recaptcha-ajax-support-2493183-226--interdiff.patch471 bytesjedihe
#226 recaptcha-ajax-support-2493183-226.patch28.67 KBjedihe
#225 recaptcha-ajax-2493183-225.patch58.09 KBsharif.elshobkshy
#217 grecaptcharender-2493183-2x3-d7.patch3.48 KBrafaelrs
#215 recaptcha-ajax-2493183-215.patch2.77 KBIvan Liaskov
#212 recaptcha-ajax-2493183-212.interdiff.txt471 bytess_leu
#212 recaptcha-ajax-2493183-212.patch28.58 KBs_leu
#199 recaptcha-ajax-2493183-197.patch28.55 KBslasher13
#197 recaptcha-ajax-2493183-196.patch22.66 KBslasher13
#195 2493183-195.patch27.69 KBiyyappan.govind
#193 recaptcha-ajax-2493183-193.patch28.55 KBslasher13
#175 interdiff-2493183-160-172.txt26.02 KBmalcolm_p
#172 recaptcha-ajax-2493183-172.patch28.48 KBmalcolm_p
#170 2493183_ajax_support_170.patch3.66 KBgregseb
#168 recaptcha_ajax_7.x-2493183-168.patch3.52 KBskylord
#164 recaptcha-ajax-2493183-164.patch8.31 KBnavneet0693
#164 interdiff-2493183-160-164.txt1.86 KBnavneet0693
#160 interdiff-2493183-156-160.txt749 byteshswong3i
#160 recaptcha-ajax-2493183-160.patch7.17 KBhswong3i
#156 recaptcha-ajax-2493183-156.patch6.48 KBhswong3i
#156 diff-136-156.txt2.07 KBhswong3i
#153 recaptcha-Ajax_Support_Behaviors-D7-2493183-153.patch4.15 KBMike Lewis
#147 recaptcha-ajax-2493183-147.patch5.26 KBjrobison
#144 recaptcha-ajax-2493183-144.patch3.61 KBjrobison
#136 recaptcha-ajax-2493183-136.patch6.59 KBhswong3i
#136 interdiff-128-136.txt652 byteshswong3i
#137 interdiff-127-128.txt210 byteshswong3i
#138 interdiff-122-127.txt4.82 KBhswong3i
#133 recaptcha-ajax-2493183-133.patch29.33 KBjohnjw59
#129 recaptcha-ajax-2493183-128.patch6.48 KBhswong3i
#127 recaptcha-ajax-2493183-127.patch6.48 KBhswong3i
#122 recaptcha-ajax-2493183-122.patch4.86 KBhswong3i
#121 recaptcha-ajax-2493183-121.patch11.07 KBhswong3i
#115 recaptcha-ajax-2493183-115.patch7.17 KBgooddenis
#114 recaptcha-ajax-2493183-114.patch7.21 KBhswong3i
#111 interdiff-2493183-110-111.txt805 bytesjames.williams
#111 recaptcha-2493183-110-ajax.patch6.9 KBjames.williams
#110 2493183-110.patch6.83 KBjofitz
#109 interdiff-2493183-108-109.txt1.78 KBjofitz
#109 2493183-109.patch13.78 KBjofitz
#108 interdiff-2493183-108-108.txt1.91 KBjofitz
#108 2493183-108.patch12.65 KBjofitz
#106 interdiff-2493183-103-106.txt2.27 KBjofitz
#106 2493183-106.patch4.63 KBjofitz
#105 interdiff-2493183-91-103.txt1.08 KBjofitz
#103 2493183-ajax-support-103.patch3.5 KBrecrit
#100 2493183_ajax_support_100.patch4.65 KBmaestrojed
#98 2493183_ajax_support_98.patch3.69 KBgregseb
#95 2493183_ajax-support_95.patch3.53 KBsimon.fryer
#91 2493183-ajax-support-91.patch3.42 KBRumyanaRuseva
#90 2493183-ajax-support-90.patch3.42 KBplov
#89 2493183-ajax-support-89.patch3.46 KBjanchojnacki
#85 2493183-ajax-support-85.patch3.43 KBvitaliyb98
#82 2493183-ajax-support-82.patch3.4 KBmertindervish
#76 2493183-recaptcha-use-behaviors-76.patch3.4 KBameymudras
#74 2493183-recaptcha-use-behaviors-74.patch3.24 KBilya.no
#71 2493183-71-ajax-support--interdiff-vs-51.patch1.06 KBjedihe
#71 2493183-71-ajax-support.patch3.49 KBjedihe
#68 2493183-recaptcha-use-behaviors-68.patch3.18 KBakozma
#51 2493183-recaptcha-use-behaviors-51.patch3.47 KBrang501
#37 interdiff.txt6.59 KBrang501
#37 2493183-recaptcha-use-behaviors-37.patch3.47 KBrang501
#28 interdiff-2493183-11-28.txt6.43 KBrang501
#28 2493183-recaptcha-use-behaviors-28.patch4.03 KBrang501
#22 Issue-2493183-by-hass-Ajax-support---Use-behaviors-f.patch3.74 KBhass
#19 1463768-recaptcha-in-modal-forms.patch2.33 KBalemadlei
#12 recaptcha-use-behaviors-11.patch3.39 KBbceyssens
#10 recaptcha-use-behaviors-10.patch3.36 KBbceyssens
#9 recaptcha-use-behaviors-9.patch3.02 KBfearlsgroove
#2 recaptcha-use-behaviors-2.patch2.13 KBfearlsgroove
recaptcha-use-behaviors-1.patch1.54 KBfearlsgroove

Issue fork recaptcha-2493183

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

Status: Needs review » Needs work

The last submitted patch, recaptcha-use-behaviors-1.patch, failed testing.

fearlsgroove’s picture

StatusFileSize
new2.13 KB

With test updates

hass’s picture

Component: General » reCAPTCHA Captcha

Do not change the g-recaptcha class name or reCAPTCHA may break! CNW therefore. See https://developers.google.com/recaptcha/docs/display

fearlsgroove’s picture

Status: Needs work » Needs review

Well, that's the point. g-recaptcha class causes the recaptcha script to apply the recaptcha automagically, which would lead to having to discover it's state before resetting or reapplying via behaviors. If we change the class name and call render explicitly we can control it via behaviors and it's trivial to make it work consistently.

hass’s picture

Status: Needs review » Needs work
fearlsgroove’s picture

Status: Needs work » Needs review

You set it back to needs work without any further comment? As I said changing the class is necessary to fix the bug. What specifically do you think this change will break?

hass’s picture

I thought this class is a must. Why are you not implementing it the way Google proposed with a callback? We may also need to fix the captcha on multiple forms per page issue. Is the recaptcha now loading slower than in past?

fearlsgroove’s picture

In my light testing it worked well, but theoretically it might try to run the behavior before the recaptcha dependencies have loaded, and since google recommends it that way ..

Here's a version that:

  • Uses the boilerplate google class for the captcha element
  • uses the google callback for the initial load
  • tells google to render explicit
  • and in the behavior defensively bails if the recaptcha api isn't available yet.
fearlsgroove’s picture

StatusFileSize
new3.02 KB

oops ..patch

bceyssens’s picture

StatusFileSize
new3.36 KB

fearlsgroove, I tested your patch in #9 but it didn't work with ajax and sometimes the grecaptcha wasn't loaded at the time the behavior was called.

The things I changed:

  • added the recaptcha api.js in #attached settings
  • changed to callback attributes to an onload attribute, as mentioned in the docs

This solution works well for us. I haven't checked the tests though.

Status: Needs review » Needs work

The last submitted patch, 10: recaptcha-use-behaviors-10.patch, failed testing.

bceyssens’s picture

StatusFileSize
new3.39 KB

When you get an error on the form, the script will try to load the widget again. But it has no css-class when it is rendered through the drupalRecaptchaOnload callback function.

I also tried to fix the tests.

hass’s picture

Status: Needs work » Needs review

Interdiffs are a cool thing :-)

Status: Needs review » Needs work

The last submitted patch, 12: recaptcha-use-behaviors-11.patch, failed testing.

hass’s picture

api.js need to be added with async and defer to the page, too.

hass’s picture

Title: Use behaviors for 2.x » Ajax support / Use behaviors for 2.x
hass’s picture

Version: 7.x-2.x-dev » 8.x-2.x-dev
hass’s picture

  1. +++ b/drupal-recaptcha.js
    @@ -0,0 +1,28 @@
    +(function ($, window, document) {
    

    - "Drupal" seems missing
    - document seems not required.

  2. +++ b/drupal-recaptcha.js
    @@ -0,0 +1,28 @@
    +Drupal.behaviors.recaptcha = {
    

    Indention incorrect

  3. +++ b/drupal-recaptcha.js
    @@ -0,0 +1,28 @@
    +  attach: function (context, settings) {
    

    What is "settings" added for?

  4. +++ b/drupal-recaptcha.js
    @@ -0,0 +1,28 @@
    +      if (typeof grecaptcha == 'undefined') {
    

    Not eslint safe. Requires "==="

  5. +++ b/drupal-recaptcha.js
    @@ -0,0 +1,28 @@
    +window.drupalRecaptchaOnload = function() {
    

    Indention incorrect

  6. +++ b/drupal-recaptcha.js
    @@ -0,0 +1,28 @@
    +    $(this).addClass('drupal-recaptcha-processed');
    

    Why is the class prefixed with Drupal? Do we have a name space collission or just prepare for any possibility?

  7. +++ b/drupal-recaptcha.js
    @@ -0,0 +1,28 @@
    +})(jQuery, window, document);
    

    - "Drupal" seems missing
    - document seems not required.

  8. +++ b/recaptcha.module
    @@ -118,20 +118,13 @@ function recaptcha_captcha($op, $captcha_type = '') {
    +                drupal_get_path('module', 'recaptcha') . '/drupal-recaptcha.js',
    

    Why is the file named "drupal-recaptcha" and not only "recaptcha"?

alemadlei’s picture

StatusFileSize
new2.33 KB

This is a patch I did while experiencing https://www.drupal.org/node/1463768 (reCAPTCHA in Modal Forms)

Works against 7.x-2.0. Should work with dev too, but didn't test.

hass’s picture

We schould move forward with #12 only.

alemadlei’s picture

Does #12 work with ajax forms?

hass’s picture

Status: Needs work » Needs review
StatusFileSize
new3.74 KB

Ported #12 to D8 and fixed the issues. However I have no idea how I can test this with Ajax under D8.

Status: Needs review » Needs work

The last submitted patch, 22: Issue-2493183-by-hass-Ajax-support---Use-behaviors-f.patch, failed testing.

hass’s picture

Status: Needs work » Needs review
Related issues: +#2548325: Schema errors for captcha.settings

Bug in captcha module

mozh92’s picture

#12 work for me, Thanks!

hass’s picture

You need to test the latest version.

rang501’s picture

#12 is not working correctly with aggregation with some cases. https://www.google.com/recaptcha/api.js needs to be specified as external. Made a small patch for it. This is for D7.

Status: Needs review » Needs work

The last submitted patch, 28: 2493183-recaptcha-use-behaviors-28.patch, failed testing.

The last submitted patch, 28: 2493183-recaptcha-use-behaviors-28.patch, failed testing.

The last submitted patch, 28: 2493183-recaptcha-use-behaviors-28.patch, failed testing.

The last submitted patch, 28: 2493183-recaptcha-use-behaviors-28.patch, failed testing.

The last submitted patch, 28: 2493183-recaptcha-use-behaviors-28.patch, failed testing.

The last submitted patch, 28: 2493183-recaptcha-use-behaviors-28.patch, failed testing.

The last submitted patch, 28: 2493183-recaptcha-use-behaviors-28.patch, failed testing.

vlad.dancer’s picture

@rang501, Thanks for patch it applies to latest 2.x, but
- should be applicable from the root of the module folder
- needs to rewrite according to the notes from here https://www.drupal.org/node/2493183#comment-10199293

rang501’s picture

StatusFileSize
new3.47 KB
new6.59 KB

The patch should be fine now.

rang501’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 37: 2493183-recaptcha-use-behaviors-37.patch, failed testing.

The last submitted patch, 37: 2493183-recaptcha-use-behaviors-37.patch, failed testing.

The last submitted patch, 37: 2493183-recaptcha-use-behaviors-37.patch, failed testing.

The last submitted patch, 37: 2493183-recaptcha-use-behaviors-37.patch, failed testing.

The last submitted patch, 37: 2493183-recaptcha-use-behaviors-37.patch, failed testing.

The last submitted patch, 37: 2493183-recaptcha-use-behaviors-37.patch, failed testing.

The last submitted patch, 37: 2493183-recaptcha-use-behaviors-37.patch, failed testing.

vlad.dancer’s picture

Version: 8.x-2.x-dev » 7.x-2.x-dev
Status: Needs work » Needs review

Change to 7.x-2.x-dev to test latest path. Will be back later to the original version.

Status: Needs review » Needs work

The last submitted patch, 37: 2493183-recaptcha-use-behaviors-37.patch, failed testing.

The last submitted patch, 37: 2493183-recaptcha-use-behaviors-37.patch, failed testing.

vlad.dancer’s picture

Version: 7.x-2.x-dev » 8.x-2.x-dev
hass’s picture

The D8 version need to be done very first.

rang501’s picture

Version: 8.x-2.x-dev » 7.x-2.x-dev
Status: Needs work » Needs review
StatusFileSize
new3.47 KB

There was an error in tests, I think I was able to fix that.

Status: Needs review » Needs work

The last submitted patch, 51: 2493183-recaptcha-use-behaviors-51.patch, failed testing.

The last submitted patch, 51: 2493183-recaptcha-use-behaviors-51.patch, failed testing.

The last submitted patch, 51: 2493183-recaptcha-use-behaviors-51.patch, failed testing.

The last submitted patch, 51: 2493183-recaptcha-use-behaviors-51.patch, failed testing.

The last submitted patch, 51: 2493183-recaptcha-use-behaviors-51.patch, failed testing.

The last submitted patch, 51: 2493183-recaptcha-use-behaviors-51.patch, failed testing.

The last submitted patch, 51: 2493183-recaptcha-use-behaviors-51.patch, failed testing.

hass’s picture

Version: 7.x-2.x-dev » 8.x-2.x-dev
grahor_targ’s picture

#19 worked for me, for ctools modal window. Tested extensively.

rajab natshah’s picture

Tested #51 with with 2.2 and Drupal 7.52

rajab natshah’s picture

Status: Needs work » Reviewed & tested by the community
hass’s picture

Status: Reviewed & tested by the community » Needs work

Patch is broken and not against D8. Do not set broken patches rtbc, please.

Patsient’s picture

all patches didnt work for me in D 8.2.4. #22 seemed more responsible, but did not work with
<a class="use-ajax" href="/form/tatata">tatata</a>

anyone have an idea how to fix this?
Please help )

rajab natshah’s picture

Noted, Hass

Aha:
hass CreditAttribution: hass commented 12 months ago
Version: 7.x-2.x-dev » 8.x-2.x-dev

It was pass for Drupal 7
Tested #51 with with 2.2 and Drupal 7.52

But you moved it to 8.x-2.x-dev

nubeli’s picture

Is it possible to use this issue to fix 7.x-2.x and create a new issue for 8.x-2.x? Maybe you've got a good reason but it seems that the 7.x patch is ready, more or less, and the 8.x patch doesn't exist yet. Aren't they independent of each other?

hass’s picture

Component: reCAPTCHA Captcha » reCAPTCHA V2
akozma’s picture

StatusFileSize
new3.18 KB

Using this patch the recaptcha scripts are attached as libraries. For me it's working now, with (modal forms) or without ajax.

Sorry for no interdiff, I had some issues while creating.

akozma’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 68: 2493183-recaptcha-use-behaviors-68.patch, failed testing.

jedihe’s picture

#51 is working for me (D7), in a setup where the form is being served via Authcache p13n (Ajax client).

I'm attaching the updated patch with a minor update to 1 trivial failure in tests.

jedihe’s picture

Version: 8.x-2.x-dev » 7.x-2.x-dev

Setting to 7.x-2.x temporarily in order to trigger full testing.

jedihe’s picture

Version: 7.x-2.x-dev » 8.x-2.x-dev

Alright, D7 tests back to green. Didn't fully check if the current tests actually check for compatibility with AJAX, though.

Back to D8.

ilya.no’s picture

StatusFileSize
new3.24 KB

Updated #68 patch for current 8.x-2.x-dev branch. Worked for me, as well. Thanks!

s_leu’s picture

Can confirm that the last patch work with the latest dev release (on a webform with ajax enabled).

ameymudras’s picture

Status: Needs work » Needs review
StatusFileSize
new3.4 KB

The last patch worked for me except for multilingual websites where the captcha would be displayed in a language the site would be first called. This would happen because recaptcha_library_info_build() function would call only once as a result all the other languages would be ignored. Ive created a patch to fix this

Status: Needs review » Needs work

The last submitted patch, 76: 2493183-recaptcha-use-behaviors-76.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

ameymudras’s picture

Issue tags: +Need tests
makbuk’s picture

#71 don't work for me.
I use reCAPTCHA 7.x-2.2 with Bootstrap Login Modal module release 7.x-3.2 for create modal registration form. Unfortunately the reCaptcha doesn't display on the registration form until you click registration button, after that the form will be closed and when you reopen it reCaptcha will be dispayed.

yago elias’s picture

Why we are keeping closing the child as duplicated to this issue? That's not the correct flow i think. None of the issues are related to each others, and keep a issue to submit patches from 7.x and 8.x is not a good idea.

artusamak’s picture

#76 is working like a charm when embedding a captcha field in an AJAX webform block.

mertindervish’s picture

StatusFileSize
new3.4 KB

I ported #76 patch for 8.x-2.2 release.

fhaupt’s picture

#76 seems to work but I get the following JS error

recaptcha__en.js:380 Uncaught Error: ReCAPTCHA placeholder element must be empty
    at zr (recaptcha__en.js:380)
    at recaptcha__en.js:385
    at c (recaptcha__en.js:375)
gurunathan’s picture

#71 working fine.

vitaliyb98’s picture

StatusFileSize
new3.43 KB

Update patch from #76

vitaliyb98’s picture

Status: Needs work » Needs review

The last submitted patch, 2493183-ajax-support-82.patch, failed testing. View results

Status: Needs review » Needs work

The last submitted patch, 85: 2493183-ajax-support-85.patch, failed testing. View results

janchojnacki’s picture

StatusFileSize
new3.46 KB

For some reason patch #85 failed to apply

plov’s picture

StatusFileSize
new3.42 KB

Adapted this patch for 8.x-2.2 version

RumyanaRuseva’s picture

Status: Needs work » Needs review
StatusFileSize
new3.42 KB

Rolled patch for 2.3.

Status: Needs review » Needs work

The last submitted patch, 91: 2493183-ajax-support-91.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

acbramley’s picture

This also seems to fix an issue with Webform where submitting a form that failed validation on another field would cause the recaptcha element to disappear.

finnsky’s picture

@acbramley on my side issue appears before #91 patch. but after patch it is gone. https://gyazo.com/a3dc3e7f1ef3dc0fdaf4598cc8434faf

simon.fryer’s picture

StatusFileSize
new3.53 KB

Unsure why, but the 71 patch no longer worked on 7.x

It was throwing a JS error about an undefined function, `render` to be specific.

Have amended the patch with the following;

if (typeof grecaptcha === 'undefined' || typeof grecaptcha.render !== "function") {

New patch is attached.

jedihe’s picture

@simon.fryer: tried applying your patch but it failed. It works if I re-save (no changes) so that it has a trailing newline at the end.

id.rem.dev’s picture

#91 Works for me with 8.5.3, but a little note about JS file location. I think it would be better to put it into "js" dir.

gregseb’s picture

StatusFileSize
new3.69 KB

We're using 7.x-2.x

Our context is a regular form loaded as part of the Document but uses an ajax enabled submit button. Like so

function mymodule_signup_form() {
...
  $form['actions']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Sign Up'),
    '#ajax' => array(
      'callback' => 'mymodule_signup_form_ajax_handler',
      'wrapper' => 'signup-form',
      'method' => 'replace',
      'effect' => 'fade'
    )
  );
...
}

#95 applied for me with the addition of a trailing newline. However both #71 and #95 have the issue for me where on the initial page load, first the onload fires, and then the behavior's "attach" method was also firing resulting in harmless but ugly errors complaining that "reCaptcha has already been rendered in this element."

Proposing to simply check if the "recaptcha-processed" class already exists both in the attach method and the window.drupalRecaptchaOnload function.

Also moved recaptcha.js into a "js" directory as recommended by @Vladimirrem

rogerrogers’s picture

I have a custom form that uses AJAX. Specifically, if a checkbox is ticked the form loads additional form elements by AJAX.

Whenever the AJAX callback fires I get an error:

An error occurred while attempting to process /system/ajax: Blocked a frame with origin "https://example.com" from accessing a frame with origin "https://www.google.com". Protocols, domains, and ports must match.

You will notice that both the example.com and google.com domains are https. I guess this being raised by Google's XSS, but not sure. It seems related to AJAX. Putting here in case someone has experienced this as well. I've applied the latest patch in this thread with no success.

To be clear, this is definitely an error caused by Recaptcha, as this form works fine without the Recaptcha enabled. It is a custom form, but it's a pretty straightforward form really - though it does use the addressfield module.

maestrojed’s picture

StatusFileSize
new4.65 KB

The patch in #98 did not apply for me to Drupal 8.5.4. I manually applied. I continued to experience this issues. I found the new recaptcha.js was throwing a 'jQuery is not defined error". IMO this is because jQuery is not loaded by default in D8. In this AJAX response, jQuery is not available.

I don't mean to take this patch a different direction but the way I know to deal with this is to define the recaptcha.js script as a library with a dependency on jQuery. This is the direction my patch goes.

After I got the recaptcha.js running without error I had errors with the recaptcha.api files from Google. I fixed this by also loading this Google Recaptcha API as a library. Note: My method no longer loads language (en) specific versions of the Google Recaptcha API. I was not sure how to get the site's configured language variable into the library's YML. This probably should be addressed. I believe this patch will only load the english version.

These two libraries are then attached to the form instead of written in the html head.

I adjusted the test to look for these JS files in the manner in which they loaded, as an attached library.

The iFrame Fallback test was also failing for me, unrelated to this issue, but I wanted the test to pass. I traced the issue to the query string part of the iframe URL. I adjusted it to be less specific in the query string. That might be less than ideal as it likely breaks the test's ability to confirm localization. I could not figure out what part of the query string was breaking the test.

Hopeful this keeps the balling rolling.

gregseb’s picture

#98 is for 7.x-2.x
I believe #91 was the last patch submitted for 8.x-2.x in fact your patch is very similar to it @maestrojed :)

---
Side rant...
Reading up I think I might share in a certain confusion... I believe this issue started out as a place to track this problem for Drupal 7, then Drupal 8 kind of showed up and started to share the space around #59

Now, I'm not really sure if this was the right place to submit a patch for 7.x-2.x though one is certainly still needed. It is also a little confusing/time-consuming to tell which patches are for which version unless it is explicitly stated in the comment.

Maybe not a huge deal, but confusing nonetheless.

maestrojed’s picture

Thanks @greagseb I missed that. I have seen the D7 and D8 confusion in other issue threads and am not clear on how to keep things straight.

#91 is probably a better option then my #100. @RumyanaRuseva has taken proper care of the localization issues I hadn't solved.

Thanks all!

recrit’s picture

Status: Needs work » Needs review
StatusFileSize
new3.5 KB

Re-roll of patch #91 that included localization support.
Changes made:

  1. moved recaptcha.js to standard js directory
  2. added check for processed class in window.drupalRecaptchaOnload
  3. code cleanup: added missing semicolon after window.drupalRecaptchaOnload, removed unused variables from trailing function arguments

Status: Needs review » Needs work

The last submitted patch, 103: 2493183-ajax-support-103.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

jofitz’s picture

StatusFileSize
new1.08 KB

An interdiff of the changes to recaptcha.js between #91 and #103 (as much for my benefit as anyone else's).

jofitz’s picture

Status: Needs work » Needs review
StatusFileSize
new4.63 KB
new2.27 KB

Minor change so that the tests will pass (does not affect functionality).

Fix a few coding standards errors.

Status: Needs review » Needs work

The last submitted patch, 106: 2493183-106.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

jofitz’s picture

Status: Needs work » Needs review
StatusFileSize
new12.65 KB
new1.91 KB

Minor changes so that the tests will pass (does not affect functionality).

Fix a coding standards error.

jofitz’s picture

StatusFileSize
new13.78 KB
new1.78 KB

Reinstate the code that calls drupalRecaptchaOnload, that was lost between #51 and #68.

jofitz’s picture

StatusFileSize
new6.83 KB

Just noticed that my last 2 patches included my BrowserTestBase file - that shouldn't have been there!
(see #2987201: Convert web tests to browser tests for more details)

Removed the irrelevant code.

james.williams’s picture

StatusFileSize
new6.9 KB
new805 bytes

AJAX behaviours may actually remove recaptcha elements from the page, so this patch adds a check for whether they exist or not before resetting/rendering them. (The attach method can still get called on the cached form element, even if it has been removed by an ajax command!)

Oops, sorry the patch file still has '110' in the name.

Status: Needs review » Needs work

The last submitted patch, 111: recaptcha-2493183-110-ajax.patch, failed testing. View results

james.williams’s picture

Issue tags: +Needs reroll
hswong3i’s picture

Issue tags: -Needs reroll
StatusFileSize
new7.21 KB

#110 reroll via latest recaptcha-8.x-2.x-dev

gooddenis’s picture

StatusFileSize
new7.17 KB

reroll via latest recaptcha-8.x-2.x-dev

gooddenis’s picture

Status: Needs work » Needs review
japicoder’s picture

Hi,
Patch #116 worked for me.

However, on certain situations it might be confusing. If your Captcha settings for "Persistence" aren't set to "Always add a challenge." it happens that after a correct validation of the reCaptcha, if the form is submitted by AJAX, the reCaptcha is not displayed again, because the Captcha module believes -by the captcha session- that the validation was ok.

gg4’s picture

Anything still blocking RTBC of this, besides additional manual testing?

james.williams’s picture

Nothing that I can see, except for japicoder's comment 117. Perhaps that would be best addressed in a follow-up though, because 'persistence' could mean different things to different AJAX scenarios, I imagine? If someone agrees, then maybe this can be considered RTBC.

Getting this through would also unblock the confusion in #2852269: Integrate Invisible reCAPTCHA option from Google.

slasher13’s picture

Status: Needs review » Reviewed & tested by the community

Tested with ajax enabled modal. Without this patch captcha wasn't visible.
After this patch captcha is visible and solvable.

hswong3i’s picture

Status: Reviewed & tested by the community » Needs review
StatusFileSize
new11.07 KB

See #122

hswong3i’s picture

StatusFileSize
new4.86 KB

#114 reroll via latest 8.x-2.x-dev, plus simplify changes to recaptcha.module.

Fix indent from #121.

Need test and review.

The last submitted patch, 121: recaptcha-ajax-2493183-121.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

Status: Needs review » Needs work

The last submitted patch, 122: recaptcha-ajax-2493183-122.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

james.williams’s picture

@hswong3i Those patches look like a lot more than a re-roll of #114/115. Please can we have an interdiff?

Given that this was already at RTBC, why were further patches necessary at all, let alone additional changes?

hswong3i’s picture

@james.williams because the upstream logic changed, so the handling of `https://www.google.com/recaptcha/api/fallback` become difficult, see #2993365: Add an option to use reCAPTCHA globally (i.e. China)

hswong3i’s picture

Status: Needs work » Needs review
StatusFileSize
new6.48 KB

@james.williams I tried for a interdiff with #114 but due to upstream changes original patch can't apply, and so interdiff failed, too.

Notes since #114:

  1. NO CHANGE to js/recaptcha.js and recaptcha.libraries.yml since #114
  2. Remove the newly recaptcha_library_info_build(), so just simply alter recaptcha_captcha() for the new query parameters
  3. Update related test cases, with similar logic and syntax with similar test cases

Test passed locally, need CI check.

james.williams’s picture

@hswong3i thanks for the explanation. I've read the patch, and I think that's all OK. I haven't done any actual testing, but I'm certainly happier now :-)

However, there were mentions previously in this ticket (e.g. comment 100) that gave the rationale for loading the scripts via libraries, rather than directly-included javascript files. I do still think that would be better to do, unless that change in approach can be justified?

hswong3i’s picture

StatusFileSize
new6.48 KB

Syntax cleanup.

hswong3i’s picture

@james.williams since I don't see @hass will accept this patch (nor the the nocaptcha patch, created since 14 Feb 2017) in a short, I would like to suggest keep this patch as similar and little change via upstream as possible. Else whenever we need to rebase the changes the workload will be similar as rewrite entirely...

I read the #100, or let's fix the language problem with other new issue, so let this patch apply as fast as possible?

james.williams’s picture

I don't see @hass will accept this patch

Why not? The patch was still needing work/review until only recently, so of course it wouldn't have been accepted before then. But it did reach RTBC in the last fortnight - as far as I understand, the only reason it isn't still there was because of the changes you had to introduce to adapt for the additional upstream changes due to #2993365: Add an option to use reCAPTCHA globally (i.e. China). So let's get this back to RTBC, then maybe hass might be happy with it?

To get there, I believe we need review from someone other than us two, and/or confirmation from someone other than you that your patch works via manual testing. (Unfortunately I don't have time myself to do that confirmation with manual testing, sorry.)

I read the #100, or let's fix the language problem with other new issue, so let this patch apply as fast as possible?

Yes, I suppose any such language issue can be split out to be dealt with separately. But comment 100 also mentioned that implementing as a library helps with ensuring jquery is available, which it isn't guaranteed to be otherwise. Anyway, I guess that could also be dealt with separately, sure. As long as both of these do get solved one way or another, fine.

hswong3i’s picture

From #129:

diff --git a/recaptcha.libraries.yml b/recaptcha.libraries.yml
new file mode 100644
index 0000000..7471b37
--- /dev/null
+++ b/recaptcha.libraries.yml
@@ -0,0 +1,6 @@
+recaptcha:
+  js:
+    js/recaptcha.js: {}
+  dependencies:
+    - core/drupal
+    - core/jquery
diff --git a/recaptcha.module b/recaptcha.module
index 8e31d9f..1d5693f 100644
--- a/recaptcha.module
+++ b/recaptcha.module
@@ -128,7 +128,14 @@ function recaptcha_captcha($op, $captcha_type = '') {
                   [
                     '#tag' => 'script',
                     '#attributes' => [
-                      'src' => Url::fromUri($recaptcha_src, ['query' => ['hl' => \Drupal::service('language_manager')->getCurrentLanguage()->getId()], 'absolute' => TRUE])->toString(),
+                      'src' => Url::fromUri($recaptcha_src, [
+                        'query' => [
+                          'hl' => \Drupal::service('language_manager')->getCurrentLanguage()->getId(),
+                          'onload' => 'drupalRecaptchaOnload',
+                          'render' => 'explicit',
+                        ],
+                        'absolute' => TRUE,
+                      ])->toString(),
                       'async' => TRUE,
                       'defer' => TRUE,
                     ],
@@ -136,6 +143,9 @@ function recaptcha_captcha($op, $captcha_type = '') {
                   'recaptcha_api',
                 ],
               ],
+              'library' => [
+                'recaptcha/recaptcha',
+              ],
             ],
           ];
         }

The problem of #100 should no longer happen, because:

  1. Order Independent: Original https://www.google.com/recaptcha/api.js is load with async defer, so it don't care if jQuery load in before nor after it
  2. jQuery MUST Exist: The library recaptcha/recaptcha is now attached TOGETHER within the $captcha['form']['recaptcha_widget'], where recaptcha/recaptcha ALREADY define the dependency with jQuery, so once the widget displayed jQuery should already load in

Simple and elegant ;-)

johnjw59’s picture

StatusFileSize
new29.33 KB

reroll #115 for latest recaptcha-8.x-2.x-dev

Status: Needs review » Needs work

The last submitted patch, 133: recaptcha-ajax-2493183-133.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

hswong3i’s picture

Status: Needs work » Needs review

@johnjw59 #128 already solve the rebase with upstream issue, plus keeping most existing logic, minimal changeset with upstream, pass test cases with CI, and working well together with #2852269: Integrate Invisible reCAPTCHA option from Google.

Please kindly review #128?

hswong3i’s picture

StatusFileSize
new652 bytes
new6.59 KB

Syntax cleanup for $captcha['form']['#attached']['library'][] = 'recaptcha/recaptcha';, better sync with #2852269: Integrate Invisible reCAPTCHA option from Google style.

hswong3i’s picture

StatusFileSize
new210 bytes
hswong3i’s picture

StatusFileSize
new4.82 KB
hswong3i’s picture

szeidler’s picture

Thanks @hswong3i. Patch #136 seems to work fine for me with 8.x-2.x-dev and webform 8.x-5.0-rc21.

james.williams’s picture

Status: Needs review » Reviewed & tested by the community

I think we can put this back to RTBC then? Thanks @szeidler!

gg4’s picture

Latest patch LGTM

marysmech’s picture

I just tested patch #136 on Drupal 8.6.2 with webform 8.x-5.0-rc23 and recaptcha 8.x-2.x-dev. It seems to fix all problems with webform ajax and recaptcha. Thank you!

jrobison’s picture

Version: 8.x-2.x-dev » 8.x-2.3
StatusFileSize
new3.61 KB

This patch works for 8.x-2.3.0.

gg4’s picture

Version: 8.x-2.3 » 8.x-2.x-dev

Please keep the version set to the latest dev applicable for the issue.

gg4’s picture

@hass Anything else you would like to see to move this forward?

jrobison’s picture

StatusFileSize
new5.26 KB

Sorry about that @bonus. I didn't realize it changed the whole version.

Also, ignore my patch for 2.3.0 at #144. Had a bug I missed. This one should work for 2.3.0.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 147: recaptcha-ajax-2493183-147.patch, failed testing. View results

gg4’s picture

Status: Needs work » Reviewed & tested by the community

Back to RTBC for #136.

lamp5’s picture

Hmm maybe I did something wrong, but according to this doc, in drupal 8 webform module, is possible to show this form in dialog window (It works!), but recaptcha does not work, also after apply latest patch. Any idea??

Update:
I think that we should attach globally reCaptcha js if we want to use it with dialog window.

function mymodulel_page_attachments(array &$attachments) {
  $recaptcha_src = 'https://www.google.com/recaptcha/api.js';
  $attachments['#attached']['html_head'] = [
    [
      [
        '#tag' => 'script',
        '#attributes' => [
          'src' => Url::fromUri($recaptcha_src, [
            'query' => [
              'hl' => \Drupal::service('language_manager')
                ->getCurrentLanguage()
                ->getId(),
              'onload' => 'drupalRecaptchaOnload',
              'render' => 'explicit',
            ],
            'absolute' => TRUE,
          ])->toString(),
          'async' => TRUE,
          'defer' => TRUE,
        ],
      ],
      'recaptcha_api',
    ],
  ];
}
gg4’s picture

@lamp5 That sounds like an interesting discussion for a followup issue. @hass Would you mind looking at #136? It has several RTBCs at this point.

hswong3i’s picture

@hass #136 still working fine with latest 8.x-2.x-dev, any else follow up required?

Mike Lewis’s picture

I backported #136 for Drupal 7. I was having some issues and this solved it.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 153: recaptcha-Ajax_Support_Behaviors-D7-2493183-153.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

gg4’s picture

Status: Needs work » Reviewed & tested by the community

Back to RTBC for #136

hswong3i’s picture

StatusFileSize
new2.07 KB
new6.48 KB

Patch #136 reroll via 8.x-2.x-dev...

No interdiff (just diff) could be given due to following error message:

1 out of 3 hunks FAILED -- saving rejects to file /tmp/interdiff-1.5vpeXE.rej
interdiff: Error applying patch1 to reconstructed file

How annoying for a RTBC issue...

peetrovich’s picture

Patch #51 solved the issue for me.
Drupal 7.61
reCAPTCHA 7.x-2.2
Webform 7.x-4.17
Webform AJAX 7.x-1.1

maestro888’s picture

Patch #156 solved the issue.
Drupal 8.6.5
recaptcha 8.x-2.x-dev

skylord’s picture

#98 for Drupal 7.61 with last Webform and Recaptcha works OK, thanks.

hswong3i’s picture

Related issues: +#2893656: Getting a "CAPTCHA session reuse attack detected" error.
StatusFileSize
new7.17 KB
new749 bytes

Sorry that I keep facing below error message (e.g. at /user/login):

CAPTCHA validation error: unknown CAPTCHA session ID. Contact the site administrator if this problem persists.

Most likely #2893656-8: Getting a "CAPTCHA session reuse attack detected" error. related issue, and so backport changes as below:

diff -u b/recaptcha.module b/recaptcha.module
--- b/recaptcha.module
+++ b/recaptcha.module
@@ -85,9 +85,10 @@
             '#value' => 'Google no captcha',
           ];

-          // As the validate callback does not depend on sid or solution, this
-          // captcha type can be displayed on cached pages.
-          $captcha['cacheable'] = TRUE;
+          // Prevent "CAPTCHA validation error: unknown CAPTCHA session ID"
+          $captcha['cacheable'] = FALSE;
+          $captcha['form']['captcha_response']['#cache'] = ['max-age' => 0];
+          \Drupal::service('page_cache_kill_switch')->trigger();

           // Check if reCAPTCHA use globally is enabled.
           $recaptcha_src = 'https://www.google.com/recaptcha/api.js';

Hopefully this fix the problem :-(

idebr’s picture

Status: Reviewed & tested by the community » Needs work

There are a few issues with the latest 8.x-2.x patch in #160:

  1. The grecaptcha library is not available when loading reCaptcha through Ajax, causing an early returns in js/recaptcha.js. The reCaptcha is not displayed to visitor. The grecaptcha global needs to be loaded through a library for it to be executed correctly. The last patch that included this change is #111.
  2. The issue is tagged as 'Needs tests' to show reCaptcha is now executed in content loaded through Ajax, but the patch does not include a JavaScript test.
  3. The current assertion to check if reCaptcha is executed only checks for the existence of the rendered markup where the reCatcha should be loaded, but not if the reCaptcha javascript is actually executed. The existing browser ReCaptchaBasicTest cannot test this, because it does not execute JavaScript.
danyg’s picture

patch #51 worked for me (D7.60, CTools Auto-modal 7.x-1.1, reCAPTCHA 7.x-2.2 + mailchimp + custom form)
It has only one problem, the recaptcha.js was located in the root folder I had to move it into recaptcha folder manually.
Thanks for it!

zain.hassan’s picture

There's a typo in recaptcha.js of #115 which ends up throwing an exception in console:

@@ -76,7 +76,7 @@
       });
       if (Drupal.ajax && Drupal.ajax.instances) {
         $(Drupal.ajax.instances).each(function (idx, instance) {
-          if (instance.$form && instance.$form && !instance.recaptcha) {
+          if (instance && instance.$form && !instance.recaptcha) {
             var recaptcha_div = instance.$form.find('.g-recaptcha');
             if (recaptcha_div.length) {
               var existing_beforeSubmit = instance.options.beforeSubmit;
navneet0693’s picture

Add grecaptcha library.

navneet0693’s picture

Status: Needs work » Needs review
jsst’s picture

Status: Needs review » Reviewed & tested by the community

Patch #164 resolves the issue: recaptcha is shown after form errors using ajax submission.

idebr’s picture

Status: Reviewed & tested by the community » Needs work

The remarks in #161.2 and #161.3 have not been addressed yet.

skylord’s picture

StatusFileSize
new3.52 KB

Reroll of #98 for 7.x-2.3

penone’s picture

When I add patch #168 the recaptcha check box is no longer showing up and am seeing the following error in dev consol:

reCAPTCHA couldn't find user-provided function: drupalRecaptchaOnload

Disregard. I see now that the recaptcha.js file needs to be moved to a js folder within the module folder.

gregseb’s picture

StatusFileSize
new3.66 KB

For 7.x-2.x
Re-roll of #98

Edit: Gah, sorry, I'm on auto-pilot. Use #168

gregseb’s picture

malcolm_p’s picture

StatusFileSize
new28.48 KB

I've built on some of the updates in #164 / #111 using a library while also preserving the cacheable captcha form element & the use_globally feature. This update uses a ConfigEventSubscriber to rebuild the library_info cache when the use_globally setting is changed. I've also removed the html_head script tag from the captcha element.

I've added a Javascript WebDriver test for a form loaded via ajax and submitted/validated via AJAX. This test also allows testing of the verified recaptcha submission.
Changes in the existing ReCaptchaBasicTest are to errors I was receiving with assertions expecting strings and receiving TranslatableMarkup and using element selectors rather than text search for the g-recaptcha element (fails with twig debugging enabled).

reszli’s picture

Patch #172 works like a charm! Thanks!

james.williams’s picture

@malcolm_p any chance of an interdiff to aid reviewers please? Or do your changes mean an interdiff isn't really applicable?

malcolm_p’s picture

StatusFileSize
new26.02 KB

@james.williams Sure, I started from # 160 so there are a lot of code additions from #111 merging that functionality as well.

nicolas bouteille’s picture

Applied #168 manually on 7.x-2.3 - it worked perfectly! Thanks!

nicolas bouteille’s picture

Applied #172 on 8.x-2.4 with git and it works thanks!

marysmech’s picture

I just applied #172 on 8.x-2.4 via composer. Tested on webform 8.x-5.1 everything seems to work. Thank you.

hswong3i’s picture

Today I give a reroll to #2493183: Ajax support / Use behaviors again...

Similar as #2493183-180: Ajax support / Use behaviors commented...
I am not a big fans for adding in more fix...
It already get stuck since 22 May 2015...
At least #160 working happily for my client(s) for more then 3 months...
Please kindly let it RTBC...

balazswmann’s picture

I have applied #172 on 8.x-2.4 via composer and looks like it solved my problem:

due to BigPipe (enabled by default since 8.5.x in the standard profile) the main document frame (with <head>...<head>) arrives first and blocks arrive later via AJAX. In these cases ['#attached']['html_head'] in recaptcha_captcha() won't take any effect and the required https://www.google.com/recaptcha/api.js won't be loaded at all. That's why the reCAPTCHA widget is not rendered in 8.x-2.4 when it appears in a block.

ccasals’s picture

Status: Needs work » Reviewed & tested by the community

We also confirm #172 works.

The last submitted patch, 168: recaptcha_ajax_7.x-2493183-168.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

david.qdoscc’s picture

#172 did not apply cleanly for us on 8.x-2.x (see below) however #164 works fine for us.

$ git apply -v recaptcha-ajax-2493183-172.patch
Checking patch js/recaptcha.js...
Checking patch recaptcha.libraries.yml...
Checking patch recaptcha.module...
Checking patch recaptcha.services.yml...
Checking patch src/EventSubscriber/RecaptchaSettingsConfigSubscriber.php...
Checking patch tests/modules/recaptcha_test/config/install/captcha.captcha_point.recaptcha_test_ajax_form.yml...
Checking patch tests/modules/recaptcha_test/recaptcha_test.info.yml...
Checking patch tests/modules/recaptcha_test/recaptcha_test.routing.yml...
Checking patch tests/modules/recaptcha_test/src/Controller/RecaptchaTestAjaxFormController.php...
Checking patch tests/modules/recaptcha_test/src/Form/RecaptchaTestAjaxForm.php...
Checking patch tests/src/Functional/ReCaptchaBasicTest.php...
error: while searching for:
    $edit['recaptcha_secret_key'] = '';
    $this->drupalPostForm('admin/config/people/captcha/recaptcha', $edit, t('Save configuration'));

    $this->assertSession()->responseContains(t('Site key field is required.'), '[testReCaptchaConfiguration]: Empty site key detected.');
    $this->assertSession()->responseContains(t('Secret key field is required.'), '[testReCaptchaConfiguration]: Empty secret key detected.');

    // Save form with valid values.
    $edit['recaptcha_site_key'] = $site_key;
    $edit['recaptcha_secret_key'] = $secret_key;
    $edit['recaptcha_tabindex'] = 0;
    $this->drupalPostForm('admin/config/people/captcha/recaptcha', $edit, t('Save configuration'));
    $this->assertSession()->responseContains(t('The configuration options have been saved.'), '[testReCaptchaConfiguration]: The configuration options have been saved.');

    $this->assertSession()->responseNotContains(t('Site key field is required.'), '[testReCaptchaConfiguration]: Site key was not empty.');
    $this->assertSession()->responseNotContains(t('Secret key field is required.'), '[testReCaptchaConfiguration]: Secret key was not empty.');
    $this->assertSession()->responseNotContains(t('The tabindex must be an integer.'), '[testReCaptchaConfiguration]: Tab index had a valid input.');

    $this->drupalLogout();
  }

error: patch failed: tests/src/Functional/ReCaptchaBasicTest.php:84
error: tests/src/Functional/ReCaptchaBasicTest.php: patch does not apply
Checking patch tests/src/Functional/RecaptchaJavascriptTest.php...
keerthithavas’s picture

I have applied #172 8.x-2.x and it does not work for me.AJAX recaptcha is still not working.
please kindly let me know how to fix it by apply patch.

kovtunos’s picture

#172 works for me. Before applying had problems with displaying Recaptcha on comment form. On Webforms it had worked fine.

ghalenir’s picture

I have a form with File field to allow user to attach documents and uses recaptcha module but I can't submit the form. I pass captcha challenge and verify before I submit the form but this recaptcha module keeps blocking and I can't submit the form. This is the error I get in the log.

webform_submission_psa_leads_test_form post blocked by CAPTCHA module: challenge reCAPTCHA (by module recaptcha), user answered "Google no captcha", but the solution was "4b4ec7d3ccf0422bb4b865b1a0a554d09fcadda0cab4ff1ee04b320b059bead4".

None of the above patches works for me.

ivan.chavarro’s picture

The patch #172 works for me, thank you.

pglynn’s picture

#172 works for me as well. Loads with contact form ajax enabled.

anybody’s picture

#172 is working perfectly for us since several months now. The ones reporting that patch #172 doesn't work for them: Could you please describe in detail:
1. If recaptcha is working as expected for you WITHOUT the patch
2. What's your specific use-case for recaptcha (HOW are you using it)
3. What's the problem appearing and how can we reproduce it?

Thank you!

mudassar774’s picture

#172 works fine for us -:)

malcolm_p’s picture

It would also be useful to hear from anyone who isn't getting #172 to work for them if they are using any other modules or customizations that might interfere with the captcha on the form.

Also any kind of failing tests would be greatly appreciated as it gives us something to work off of to get this issue to RTBC.

pobster’s picture

Everyone reporting that it works seems to be mentioning that they're applying it to 8.x-2.4 ~ a tagged release. It doesn't apply cleanly to HEAD, it just needs rerolling that's all.

slasher13’s picture

Issue tags: -Need tests
StatusFileSize
new28.55 KB

re-roll for 8.x-2.x-dev

anybody’s picture

Any plans for a new release?

iyyappan.govind’s picture

StatusFileSize
new27.69 KB

Hi I tried to apply the patch with stable release 8.x-2.4 but patch apply failed. So checked with git apply --check . But it shows ReCaptchaBasicTest file has some error at line 87. So re-rolled the patch for stable version. I know it is working for dev version of module. But it will be helpful for stable release version.

cjsmith87’s picture

I am using 8.x.2.5 and it still appears to be broken? How can I apply the patch to this version please?

slasher13’s picture

StatusFileSize
new22.66 KB

re-roll after 2.5 release

slasher13’s picture

slasher13’s picture

StatusFileSize
new28.55 KB

fix imcomplete patch from #197

cjsmith87’s picture

I have downloaded and unzipped a copy 8.x.2.5 to "C:\Patch\recaptcha", downloaded the patch and am using TortoiseSVN to apply the patch. When i do so it says "C:\Patch\recaptcha" is not a valid working copy? In the folder I have folders like "config", "src" and "recaptcha-php" but the patch seems to be looking for a "js" folder? Sorry, I am new to this!

cjsmith87’s picture

Ignore me, used git and it worked perfectly. Thanks!

iyyappan.govind’s picture

dimitriskr’s picture

#199 on 8.8.2, recaptcha 2.5.0 and webform 5.8.0 works good!

nicolas s.’s picture

With patch on #199 form recaptcha (2.5.0) appear on my modal but I trie to submit this I have recaptcha error The answer you entered for the CAPTCHA was not correct. when I checked well recaptcha

jedihe’s picture

#199 works great for me, applied it on top of 8.x-2.5.

My setup:

- reCaptcha v3, using reCaptcha as fallback.
- AJAX-submitted form: #199 gets reCaptcha to show up after a submission fails reCaptcha_v3 validation; without the patch, it didn't show (due to missing Drupal behavior).
-- Submitting without solving reCaptcha shows the proper validation error.
-- Submitting after solving reCaptcha gets the submission to succeed.
- Normally-submitted form: reCaptcha shows up after a submission fails reCaptcha_v3 validation; this was working fine before applying #199.

Mido_739’s picture

#199is work for me Thanks!

wil2091’s picture

Thanks! #199 worked for me too.

alfattal’s picture

I've applied the patch in #199 months ago (Can't remember when exactly!) and it worked perfectly, but recently, I'm experiencing the same issue again. I'm on Drupal 8.9.2 using reCAPTCHA version 8.x-2.5.

oheller’s picture

Status: Reviewed & tested by the community » Needs work

The ajax submit has stopped working for anonymous users after completing the recaptcha and submitting the webform.

The expected behavior is when I submit my webform the form is replaced with the success message. This happens if I'm logged in or if I submit the form without validation, get the Drupal captcha error, then complete the recaptcha, then submit the webform.

I am using Drupal 8.9.2, webform 5.19, catcha 1.1.0 and tested with recaptcha [2.x-dev, 2.5 and 3.0].

sonfd’s picture

Patch from #199 is working for me with D 8.91, webform 5.18, ReCaptcha 3.0.

For those reporting that it stopped working, can you confirm that the patch was still applied? Could your issue be that you performed an update and for some reason this patch was not reapplied?

alfattal’s picture

@sonfd Yes, I can confirm that the patch in #199 stopped working while it is still applied.

s_leu’s picture

I need to test the patch on Drupal 9, but it wouldn't work due to the missing core_version_requirement in the info file of the test module added in this patch.

Thus here a patch that makes the module with this patch applied work on D9.

h0ly_danc3r’s picture

Im getting error in console reCAPTCHA couldn't find user-provided function: drupalRecaptchaOnload after patching and recaptcha is in module/js.recaptcha. What could it be?

percoction’s picture

@s_leu thank you for that update. I can confirm the patch in #212 fixes an issue we were now seeing now running Functional tests in our custom modules:
Drupal\Core\Extension\InfoParserException: The 'core_version_requirement' constraint (9.0.7) requires the 'core' key not be set in modules/contrib/recaptcha/tests/modules/recaptcha_test/recaptcha_test.info.yml

Ivan Liaskov’s picture

StatusFileSize
new2.77 KB

Hi, guys.
I got another take on the problem and kind of applied solution from https://www.drupal.org/project/recaptcha/issues/1463768
It works for us and if you desperate - try it.

vlyalko’s picture

confirming that patch #215 fixed the issue for us

rafaelrs’s picture

StatusFileSize
new3.48 KB

Updating the #71 patch to make it work correctly on 7.x-2.3.
I also added a new verification to make sure that the code won't break when some functions are not defined yet.

james.williams’s picture

The patch for D7 from @rafaelrs is a re-roll of #71, but there was a patch in #168 for D7 that added a fix because there were issues identified with #71.

Regardless, given that #2875698: Drupal 7.x: Ajax support / Use behaviors for 2.x and #1463768: reCAPTCHA in Modal Forms exist for getting this kind of functionality into D7, I suggest this ticket should ONLY be used for D8 work?

Meanwhile, I've hidden what I believe are the oldest patches, so just the 'tips' of each 'branch' of work remain shown for review.

steven jones’s picture

To that end I've posted an updated Drupal 7 patch to #2875698-15: Drupal 7.x: Ajax support / Use behaviors for 2.x.

yuri morato duarte’s picture

In my case, I needed to "recreate" the recaptcha after my webform validation:

grecaptcha.ready(function () {
        var el = $('.g-recaptcha', context);
        if (el.length > 0 && el.children().length == 0) {
          grecaptcha.render(el.get(0), {
            sitekey: el.data('sitekey'),
            theme: el.data('theme')
          });
        }
      });

By doing this on a JavaScript behaviour that's loaded on the page I was able to make it work.
My recaptcha is currently at version 8.x-3.0

jonnyeom’s picture

Just an update on patch #199,

It is working for me so far on Drupal 8.9.13, Recaptcha 3, Captcha 1.1

baltazarz3’s picture

#220 worked for me, I was having problems with Webform + ajax. The Javascript worked perfect for version 2.5.
Thank so much Yuri Morato Duarte, great work around.

kburakozdemir’s picture

#199 worked for me.

Drupal core 8.9.16
CAPTCHA 8.x-1.2
reCAPTCHA 8.x-3.0

Thank you.

lukasss’s picture

#199 worked for me.

Drupal core 9.1.8
reCAPTCHA 8.x-3.x-dev

Thank you!

sharif.elshobkshy’s picture

StatusFileSize
new58.09 KB

Drupal 9.1.9
reCaptcha 3.0

$drush updb -y
The 'core_version_requirement' constraint (9.1.9) requires the 'core' key not be set in modules/contrib/recaptcha/tests/modules/recaptcha_test/recaptcha_test.info.yml

Updated patch #199.

jedihe’s picture

Updating #225:

  • Remove leftover .patch file
  • Add back core: 8.x in the test module, to match recaptcha.info.yml

The interdiff does not include the removal of the .patch file.

This is #199, updated to apply on recaptcha 3.x (3.0 in my case), running on Drupal 9.1.9.

jedihe’s picture

StatusFileSize
new28.74 KB
new664 bytes

Let's try to fix the tests error in D9.

jedihe’s picture

StatusFileSize
new28.77 KB
new841 bytes

RecaptchaJavascriptTest::getMessages() depends on a class not used in 'stark' markup. Let's try fixing the tests by targeting data-drupal-messages instead.

jedihe’s picture

Status: Needs work » Needs review
thirstysix’s picture

#228 Patch works well with Drupal 9.2.1 &
reCaptcha 3.0

thirstysix’s picture

Version: 8.x-2.x-dev » 8.x-3.0
Status: Needs review » Reviewed & tested by the community
markdc’s picture

#228 also works with Drupal 8.9.16 / reCaptcha 3.0. Thanks!

anybody’s picture

Confirming RTBC!

Please note that this afterwards needs backport to Drupal 7 in #2875698: Drupal 7.x: Ajax support / Use behaviors for 2.x as it's also broken there!

anybody’s picture

Version: 8.x-3.0 » 8.x-3.x-dev
Issue tags: +Needs backport to D7

Any plan to commit this long and long outstanding issue?

davisa’s picture

Patch #228 doesn't seem to work in my case - Drupal 9.2.7.
Same issue - allows the webform to be submitted without actually completing the recaptcha.

npcoder’s picture

StatusFileSize
new144.23 KB

The current Drupal version is 9.2.8. I did the following steps:

  1. Installed recaptcha 8.x-3.0 using composer and enabled it
  2. Implemented on a Webform
  3. When the validation error is shown, the reCAPTCHA was invisible.

.

To fix the reCAPTCHA invisible, I used one of the patches (just a partial code), I added it to a JS file (in custom theme).

/**
   * Recaptcha bug fix with ajax rendering form.
   */
   Drupal.behaviors.recapcha_ajax_behaviour = {
    attach: function(context, settings) {
      if (typeof grecaptcha != "undefined") {
        var captchas = document.getElementsByClassName('g-recaptcha');
        for (var i = 0; i < captchas.length; i++) {
          var site_key = captchas[i].getAttribute('data-sitekey');
          if (!$(captchas[i]).html()) {
            grecaptcha.render(captchas[i], { 'sitekey' : site_key});
          }
        }
      }
    }
  }

The invisible issue was resolved but when Chrome/Firefox console is open, it showed Uncaught TypeError: grecaptcha.render is not a function error.

Uncaught TypeError: grecaptcha.render is not a function
    at Object.attach (js_guXVYGYbF5iRla6wn7Ll0pA8qLxn0RiJsZQ6-OiH11o.js:379)
    at js_nILFjJNZxNYRT8aO_nBW1pgfQQcnEE8ZZqZTMG38p_A.js:160
    at Array.forEach (<anonymous>)
    at Object.Drupal.attachBehaviors (js_nILFjJNZxNYRT8aO_nBW1pgfQQcnEE8ZZqZTMG38p_A.js:157)
    at js_nILFjJNZxNYRT8aO_nBW1pgfQQcnEE8ZZqZTMG38p_A.js:386
    at HTMLDocument.listener (js_nILFjJNZxNYRT8aO_nBW1pgfQQcnEE8ZZqZTMG38p_A.js:374)

Trying to find the patches and alternative solution, I finally figured out that it's due to the network issue where 'www.google.com' is not accessible. So following steps were taken:

  1. Checked the option "Use reCAPTCHA globally" from the reCAPTCHA setting (/admin/config/people/captcha/recaptcha) and save the configuration.
  2. If you are using 'Security Kit' , go to the configuration page (/admin/config/system/seckit).
    1. Under Content Security Policy > script-src add the following links: https://www.recaptcha.net/recaptcha/api.js https://www.recaptcha.net/recaptcha/api/fallback
  3. Clear the cache
paul_gregory’s picture

#228 patch works for us on Drupal 9.2.10 and reCAPTCHA 3.0.

This solved an issue where our Ajax webforms using reCAPTCHA V3 weren't successfully falling back to reCAPTCHA V2.

anybody’s picture

Thank you @npcoder for your detailed feedback. So that's not caused by the patch and the patch still solves the basic problem.
@DavisA could you please check if that is also the case for you? I still think the patch is a HUGE improvement and should be committed.

anybody’s picture

@recaptcha Maintainers: Any plan for a final review to get this 239 comment counting issue fixed? :)

nicolas s.’s picture

The Patch #228 works for me with a Drupal 9.3.6

localnetwork’s picture

#228 works for me.

Rajeev cp’s picture

#228 working for me Drupal version 9.3.0

mjt772’s picture

#228 is not solving this problem in my case (Drupal 9.3.12, recaptcha 8.x-3.0), and I also tried the approach in #236, but to no avail. Specifically, I have a contact form being submitted via Ajax, configured with recaptcha_v3 (8.x-1.4) to fallback to a standard v2 image recaptcha. If a user fails the v3 recaptcha on form submission, the failure message appears but the v2 image recaptcha does not, so it is then impossible for the user to submit the form. This recaptcha setup is working perfectly on my other, non-Ajax contact forms. If anyone has any other advice, I'd very much appreciate it!

akalam’s picture

I can confirm the patch #228 is working directly for me on D9.3 with the webform module

anybody’s picture

Once again confirming that the patch fixes the issue for several people (including me for the confirm). If the maintainer agrees the patch is OK from a logical perspective, tests are green and it doesn't make things worse, this should please please be committed... :( It's really a pain and unexpected that you can't use reCaptcha with Webform AJAX currently.

We can create follow-ups for the remaining issues and look at them in detail.

If someone uses cookies_recaptcha with this patch, please note it's broken: #3296032: reCaptcha protection broken with reCaptcha AJAX (patch)

anybody’s picture

Title: Ajax support / Use behaviors for 2.x » Ajax support / Use behaviors
neclimdul’s picture

Reading the patch, the of classes instead of .once was weird. Now I see why its doing it and I guess I don't have a better solution. LGTM.

zhelmet’s picture

StatusFileSize
new28.75 KB

Fixed duplicate dependencies keys in recaptcha_test install files

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 248: recaptcha-ajax-support-2493183-248.patch, failed testing. View results

Nigel Cunningham made their first commit to this issue’s fork.

slasher13’s picture

Status: Needs work » Needs review
StatusFileSize
new24.28 KB

re-roll

Status: Needs review » Needs work

The last submitted patch, 251: recaptcha-ajax-support-2493183-251.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

anybody’s picture

From #228 where no tests where failing, now 2 tests fail in #251. Are you planning to work on this @slasher13?

pobster’s picture

The failing tests are actually in a completely new file:

--- /dev/null
+++ b/tests/src/Functional/RecaptchaJavascriptTest.php

The issue is with the test code rather than in the fix:

+    $messages = $this->getMessages();
+    $this->assertNotEmpty($messages);
// Below: "assertContains(): Argument #2 ($haystack) must be of type iterable, string given".
+    $this->assertContains('Invalid email', $messages);

The getMessages() method returns a string rather than an array - so it could be fixed either by changing the assertion to look at strings or by changing the return type of this method (preferable, I don't feel like it makes too much sense to concatenate the messages into a single string).

nileema19’s picture

Passing an array of strings to assertNotContains() and assertContains() is deprecated (D9).
The assertContains and assertNotContains functions could be replaced with 'assertStringContainsString' / 'assertStringNotContainsString' to fix the patch.

nileema19’s picture

StatusFileSize
new24.34 KB
nileema19’s picture

StatusFileSize
new24.28 KB

mistakenly attached the wrong patch :(

nileema19’s picture

StatusFileSize
new24.36 KB
pobster’s picture

As I was saying above, it seems weird to concatenate all the Drupal messages into one long string. Wouldn't it be better for the tests to just change the return of the getMessages() method? Then at least the messages are checked in isolation, each message is checked separately.

/**
  * Search for messages in the last html page response.
  *
  * @return array
  */
 public function getMessages($timeout = 2000) {
   $this->getSession()->wait($timeout, '(jQuery("div[data-drupal-messages]").length > 0)');
   $page = $this->getSession()->getPage();
   $messages = $page->findAll('css', 'div[data-drupal-messages]');
   $text = [];
   if (isset($messages)) {
     foreach ($messages as $message) {
       $text[] = $message->getText();
     }
   }
   return $text;
 }

nigelcunningham’s picture

Modified the tests to use an array of messages (see merge request).

nigelcunningham’s picture

Status: Needs work » Needs review
pobster’s picture

Nice! LGTM

jospratiklive’s picture

Hi Everyone,

This might work with ajax submits, but it doesn't work with Modal popup.

Below are the markup appears in debug of captcha element.
Modal popup:
<div class="g-recaptcha" data-sitekey="{site_key}" data-theme="light" data-type="image"></div>

For direct visit to user/login form:
<div class="g-recaptcha recaptcha-processed" data-sitekey="{site_key}" data-theme="light" data-type="image"><div style="width: 304px; height: 78px;"><div><iframe title="reCAPTCHA" src="https://www.google.com/recaptcha/api2/anchor?.......

I tried hard to find the actual cause, but no success.

Can anyone please give any feedback.

Thanks!

lamp5’s picture

@jospratiklive #comment-12837396

jospratiklive’s picture

Hi @lamp5

Thanks for your reply.

May be I am doing something wrong. No success.

I am using the latest version (recaptcha module + recaptcha v3 + drupal 9)

Added your code snippet of globally load the js file. No markup of checkbox section appears in element.

For modal popup : I placed dpm($element) in file modules/contrib/captcha/src/Element/Captcha.php line no. 244 (before return $element). The captcha markup blank.

For user/login link : This does contain the markup.

Any feedback welcome!

jospratiklive’s picture

Tested webform dialog with webform ajax submission. It works.

I think something got to do with how login form is submitted vs webform ajax submission

UPDATE: Ok, got this working! I now handled the ajax submission of user login differently.

neclimdul’s picture

StatusFileSize
new6.22 KB
new2.52 KB

All the seemingly unrelated test changes are making this hard to review. Seem to be replacing deprecation on unrelated code and just "better" handling without any explanation. I don't see the point but they all seem to work.

Anyways there where a lot of patches with out a lot of notes so here's some interdiffs to make maintainer review a bit easier.

kburakozdemir’s picture

#258 worked for me.

Drupal core 9.4.8, Webform 6.1.3 "Use Ajax" setting enabled, PHP 8.0.23.

Thanks.

shani maurya’s picture

#258 worked for me.

Drupal core 9.3.22 and planning to move 9.4, ReCaptcha 8.x-3.1

Thanks.

markdc’s picture

#258 worked for me.

Drupal core 9.5.3, Ajax Comments 8.x-1.0-beta5, PHP 8.0.27.

Thank you!

anybody’s picture

slasher13’s picture

StatusFileSize
new24.05 KB

re-roll #258

rohit.rawat619’s picture

#273 Patch working fine

kissfm’s picture

Patch #273 applied successful for me. Thanks.

bbc’s picture

Patch #273 looks good to me as well. Thanks @slasher13!

kburakozdemir’s picture

Patch #273 applied successfully for me. Thanks.

altascendare’s picture

Thanks @slasher13, patch #273 works fine for me

Mustafa-salameh’s picture

patch #273 works with me

vmarchuk’s picture

Patch #273 was applied successfully and it works fine for me. Thanks.

alyaj2a’s picture

Patch #273 worked perfectly, with this patch recaptcha in modals was solved. Thanks.

damondt’s picture

Patch #273 tests good

nileema19’s picture

Patch #273 was applied successfully and it is been working fine for the webform in the modal!

Thanks @slasher13

nigelcunningham’s picture

Status: Needs review » Reviewed & tested by the community

Patch looks good to me and has been successfully tested by all the above; marking RTBC.

thirstysix’s picture

Patch #273 works.
+1 RTBC

ahmedx’s picture

Patch #273 was applied successfully and it works fine in drupal ajax modal.
Thanks @slasher13

s_bhandari’s picture

Issue summary: View changes
Status: Reviewed & tested by the community » Needs review
StatusFileSize
new24.05 KB
s_bhandari’s picture

Issue summary: View changes
StatusFileSize
new24.06 KB

Hi,

Fix for the issue of Unable to install modules: module 'recaptcha_test' is incompatible with this version of Drupal core. Please review.

Thanks.

Status: Needs review » Needs work

The last submitted patch, 288: recaptcha-ajax-support-2493183-288.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

s_bhandari’s picture

StatusFileSize
new24.05 KB

Hi,

Fix for the error The 'core_version_requirement' constraint (^8.9 || ^9 || ^10) requires the 'core' key not be set in modules/contrib/recaptcha/tests/modules/recaptcha_test/recaptcha_test.info.yml. Please review.

Thanks.

anybody’s picture

Status: Needs work » Reviewed & tested by the community

Back to RTBC for #273 with many RTBC votes.

#288 + #290 seem unrelated to this issue.

anybody’s picture

anybody’s picture

@all: Please help testing and reviewing MR!24 based on #273 so we can hopefully end this never ending story soon. Thank you!

anybody’s picture

Status: Reviewed & tested by the community » Needs review
anybody’s picture

Priority: Normal » Major
anybody’s picture

Status: Needs review » Needs work

eslint and phpcs are unhappy, but tests are green now. Could someone fix that finally?
https://git.drupalcode.org/project/recaptcha/-/pipelines/63104

Manual testing is still welcome!

kostyashupenko made their first commit to this issue’s fork.

dark05’s picture

I'm update module in 3.2.0 version with patch #273

Yashaswi18 made their first commit to this issue’s fork.

Shank115 made their first commit to this issue’s fork.

matthewmessmer’s picture

#273 fixed the initial issue of the captcha being unusable on a multistep form, but the captcha module persistence settings do not appear to be honored. The recaptcha appears on every step of the multistep form regardless of the persistence settings.

anybody’s picture

@matthewmessmer thank you! Can you elaborate, if it worked as expected without the patch? Then we should add a test for that and fix it. Would be super nice to have more community contribution here to get this finished!

ronraney’s picture

Issue summary: View changes
ronraney’s picture

Issue summary: View changes
ronraney’s picture

Issue summary: View changes

I found this issue because I was experiencing an issue on a multipage form with AJAX enabled for validation. I installed the patch #273 and now it's working, but not ideally.

To resolve the issue with the form not recognizing multipage and putting captcha on every page, I moved the captcha inside the last page, where the submit resides. It's interesting that the "I'm not a robot" is showing but not the reCAPTCHA logo on the bottom of the page. All of my other forms do not require human interaction.

Therefore, I don't know if #273 totally solves it because it appears a backup form is placed on the page, and the reCAPTCHA button is not showing on the bottom right of the page. I prefer the checkbox to a math quiz, so I'm keeping this in place, but it's my understanding there shouldn't be a form input at all.

murat_kekic’s picture

Adding to the discussion, it appears that the persistence settings were previously overlooked #3363653 and not related to the patch.

zuhair_ak’s picture

#273 worked for me also, Thanks @slasher13. Is there anyway we can commit this and fix the issue with multiform AJAX as a followup ticket

nathankg’s picture

Status: Needs work » Reviewed & tested by the community
Issue tags: -Needs backport to D7

I have tested patch #273 Thanks @slasher13

Environment tested on:
Drupal 10.1.6
Php 8.1.21

Version: Recaptcha 8.x-3.2

Issue prior to patch:
We were using a basic webform with all fields required, with ajax enabled (not multi-step) in a block to collect anonymous user feedback. With persistence set to: "Omit challenges in a multi-step/preview workflow once the user successfully responds to a challenge." and captcha added directly to the webform rather than as a captcha point within the block (however adding the captcha point within the block had the same result). If the anonymous user failed to enter one of the required fields or pass the captcha, the captcha would not display post initial submission. Disabling ajax resolved the issue but was not an option in this use case.

After applying the patch:
The captcha was shown as expected post failed webform submission within the webform block.

ryan-l-robinson’s picture

StatusFileSize
new24.05 KB

One issue I've now encountered with the patch in #273 is that it adds a new functional test, but the setUp function there does not have the void return declaration, which results in throwing an error if I try to run any functional tests. See https://www.drupal.org/project/recaptcha/issues/3446000. I added that to an updated patch here.

My editor (VS Code with a Drupal formatter) is pointing out other issues with that file, but those ones don't stop me from running other tests, so I'll leave that to those who are working on that test.

sebasgd’s picture

I have the #273 patch installed in a multilanguage website. The webform loaded using ajax works correctly in all languages. But a new webform was created in the website and that form doesn't load with ajax. The result is that the recaptcha loads in english but not in other languages. And is something in this patch because, if I remove the patch, the recaptcha in the non-ajax webform works correctly in all languages and the recaptcha in the webform loaded using ajax stops working.

iyyappan.govind’s picture

james.williams’s picture

MR24 works well for me too; thanks all!

The change added in the latest patch in #313 is already included in MR24 (it's just https://git.drupalcode.org/project/recaptcha/-/commit/e1e62e0a3fdabfb4f0...), so can be ignored as we should all be working with the merge request, not patches, nowadays. (Which is why I've also hidden all the previous patch files to try and give more prominence to the MR instead.)

@sebasgd thanks for reporting your issue about languages in #314. Please can you confirm what the language codes you have configured in Drupal are, which incorrectly showed the recaptcha element in English on your non-Ajax form? The work here assumes the language codes configured in Drupal match those that Google expects, so I wonder if it could have just been due to them not matching up? Google's documentation does say that they can auto-detect the user's language; I wonder if they do that slightly differently between the non-ajax recaptcha widget rendering, and the new explicit rendering through javascript. So could you also let us know which language(s) your browser is configured to use, to help diagnose the issue?

@Anybody thanks especially for having taken on maintainership of this module. What would you like to see happen here before merging it? Do you feel the languages issue is a blocker? I could believe it is; but otherwise maybe we need to be really strict that further change should be dealt with in follow-ups rather than drag this issue out any further?

anybody’s picture

@james.williams thank for your feedback! What would you think about a new 4.x branch starting with the changes from this issue?

It would be great if we could fix the language issue, of course, and hopefully it's not too hard? But I wouldn't see it as a hard blocker looking at the relevance and history of this issue. I very much hope it won't have a 10 years anniversary ;)

james.williams’s picture

Great! Yes, I'm all for this being in a new release soon please :) I would just stay on the 8.x-3.x branch though, it's not a backwards-compatibility break is it? If you're thinking of jumping just for the sake of using semantic versioning, I'd counter that with the fact that anyone using standard composer constraints (e.g. ^3) has to manually change their constraint, which isn't ideal - especially if there was a later security update that came with more urgency. But of course I'm not aware of your plans; maybe you have other reasons to look to break backwards-compatibility?

anybody’s picture

StatusFileSize
new25.15 KB

Current state of the MR as static patch attached for the time being.

anybody’s picture

@S_Bhandari deleted the issue summary in #287!
But it was poor in general, so could someone please create a helpful issue summary based on the template?

If someone would like to finish this, please find a fix for #314, so we can finally merge this.

james.williams’s picture

Issue summary: View changes
Status: Reviewed & tested by the community » Needs work
Issue tags: -Needs issue summary update

I've had a go at setting the issue summary, hopefully it's sufficiently accurate. Setting back to 'needs work' though to investigate/resolve that remaining possible multilingual issue then. Although as I wrote in my comment, I do wonder if it's just down to a misconfiguration which is probably out of scope to resolve here. I'll try reaching out to @sebasgd by other means to see if we can get feedback!

grevil’s picture

Very nice work! Looking good! 🙂👍

I agree with @james.williams, since we do not introduce any breaking changes here, I'd say we can safely merge this in 3.x (once the multilanguage issue is fixed).

I'll see if I can properly reproduce it.

grevil’s picture

Ok, the multilanguage bug is quite minor in my opinion. Once a new language is added and set as the default language, the recaptcha won't appear. We first need to clear all caches before the captcha appears (with the correct language set. Tested it with spanish, german and french as both the default language and per url language prefix).
Switching the default language to an already added language works flawlessy and without clearing any caches.

I tested this through the login captcha endpoint (no ajax) and through our test endpoint (/recaptcha-test) both use the currently set language as expected.

Furthermore, this little newly added language bug is also happening in 3.x, so it's unrelated to this issue anyway. Cleaning up the code a bit now.

anybody’s picture

Re #323 thanks @Grevil!

Could you then please create an issue for that? Sounds like cache tags or contents are missing then, but I agree it's an edge-case and unrelated then. No blocker for this issue.

grevil’s picture

Oh no, the fact that we are using external scripts hosted by Google probably makes this not DSGVO compliant...

Let's see what @Anybody has to say about this.

anybody’s picture

@Grevil: No, recaptcha is external 3rd party by definition. There's no way around the external script loading. Not related to this issue and if someone needs a solution, there's COOKiES recaptcha submodule for example.

People using recaptcha have to be aware of the data privacy consequences generally!

grevil’s picture

Status: Needs work » Reviewed & tested by the community

Ah, of course, my bad.

Alright! Everything else is fine! Fixed the remaining js and phpcs issues. Tests are good and all green! Couldn't reproduce the multilanguage bug after extensive testing. All good from my site!

RTBC!

anybody’s picture

Thanks all! Okay then let's do it! I'm going to merge this one after 328 comments. I hope this doesn't only feel great for all of us, but also works well! 🎉

  • Anybody committed 7f1024c3 on 8.x-3.x
    Issue #2493183 by Anybody, hswong3i, slasher13, rang501, fearlsgroove,...
grevil’s picture

Status: Reviewed & tested by the community » Fixed
james.williams’s picture

Thank you so much!

ryan-l-robinson’s picture

Will this be in a stable release within the next few days?

We're close to deploying an update to production, and the patch doesn't work against the stable release anymore, so I think I need to put the dev release into production if there isn't stable soon, which I am generally not eager to do.

anybody’s picture

@ryanrobinson_wlu yes, let's do it! No complaints since merge, I'll tag a new stable release containing this.

ryan-l-robinson’s picture

Thank you!

xeiro’s picture

Patch was working for me on 10.2.6 php 8.1 however, none of the patches or module versions apply for 10.3.2. Beware if invisible captcha is placed on login pages, user will be locked out and have to disable or uninstall via drush/db.

anybody’s picture

@xeiro I don't really get your point.
This issue is fixed in recaptcha 8.x-3.4! No more patch needed for this.

xeiro’s picture

@Anybody, sorry, I posted to the wrong issue. 2852269 - "Integrate Invisible reCAPTCHA option from Google" was my issue and I posted the relative info there. All good now, thanks.

Status: Fixed » Closed (fixed)

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