Currently there is no option to enable JavaScript call back attribute to be attached to g-recaptcha div (where all attributes get for recaptcha gets attached to) and there's no other way to do this other than modifying in recaptcha.module file itself.

Attached is patch with hard coded data-callback attribute which calls captchaCB function in global JavaScript namespace. Is it possible to add this field in settings to call different function?

CommentFileSizeAuthor
#27 no-option-for-data-callback-2822129-27.patch2.59 KBrelim
#26 2822129-26-D8.patch2.53 KBselva.swamy@gmail.com
#23 2822129-23-D8.patch2.5 KBselva.swamy@gmail.com
#21 2822129-21.patch2.5 KBiyyappan.govind
#20 2822129-20.patch2.5 KBiyyappan.govind
#19 2822129-19.patch2.55 KBiyyappan.govind
#17 no-option-for-data-callback-2822129-17.patch2.61 KBljcarnieri
#16 no-option-for-data-callback-2822129-16.patch2.55 KBljcarnieri
#15 recaptcha_grecaptchaCallback.patch1.29 KBmalcolm_p
#2 recaptcha_callback.patch533 bytesrmatsumoto
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

rmatsumoto created an issue. See original summary.

yang_yi_cn’s picture

btw this feature is regarding

You can get the user’s response in one of three ways:

g-recaptcha-response POST parameter when the user submits the form on your site

grecaptcha.getResponse(opt_widget_id) after the user completes the CAPTCHA challenge

As a string argument to your callback function if data-callback is specified in either the g-recaptcha tag attribute or the callback parameter in the grecaptcha.render method

in https://developers.google.com/recaptcha/docs/verify (Verifying the user's response).

The use case is:
- when page load the form submit button is disabled.
- only when user send the correct answer, the button will be enabled by javascript callback.

yang_yi_cn’s picture

Status: Active » Needs review

Status: Needs review » Needs work

The last submitted patch, 2: recaptcha_callback.patch, failed testing.

The last submitted patch, 2: recaptcha_callback.patch, failed testing.

The last submitted patch, 2: recaptcha_callback.patch, failed testing.

The last submitted patch, 2: recaptcha_callback.patch, failed testing.

The last submitted patch, 2: recaptcha_callback.patch, failed testing.

The last submitted patch, 2: recaptcha_callback.patch, failed testing.

The last submitted patch, 2: recaptcha_callback.patch, failed testing.

hass’s picture

Maybe patch in #2847732: enable configurable data-callback attribute is a better starting point, but I'm sure it has a serious security issue.

hass’s picture

onSuccess is used in https://www.google.com/recaptcha/api2/demo, but that could conflict in Drupal. We should prefix with the module name to be safe.

hass’s picture

Can we do this with a Drupal.behaviors or anything else I may never used yet? So that every module can register a callback and there is no need to hardcode it?

malcolm_p’s picture

Here's an updated patch that adds a JS library with the callback function in the api.js to prevent the grecaptcha error. I wouldn't say this is a great solution, but I wanted the grecaptcha.getResponse() to check if a recaptcha was submitted and this allows the JS to be loaded.The callback must be in the global scope so Drupal.behaviors isn't an option.

ljcarnieri’s picture

ljcarnieri’s picture

This patch uses the same solution, but resolve of conflict between the patch: #2493183: Ajax support / Use behaviors for version 8.x-2.3.
Motivation: I'm using the version 8.x-2.3 with this other patched applied by composer.json.

leofishman’s picture

This may be a silly question, but the callback function should be in a global scope? I can't get reCaptcha to see it.

thanks

iyyappan.govind’s picture

Hi Folks, I tried to apply the #17 patch and I already applied the #2493183: Ajax support / Use behaviors for 2.x . But I got failed to apply patch.
So I rerolled the patch with the stable version of the module.

iyyappan.govind’s picture

Hi Folks uploaded wrong patch. Here is the correct one.

iyyappan.govind’s picture

The previous patch has syntax errors. Sorry for that. I updated the patch.

selva.swamy@gmail.com’s picture

Looks like there are still some issues with patch as testing failed. Kindly update and mark "Needs Review".

selva.swamy@gmail.com’s picture

Updated is the corrected patch which has been re-rolled. Also tested this feature and it is working as expected. I think after another review this issue can be marked as RTBC.

selva.swamy@gmail.com’s picture

Status: Needs work » Needs review
selva.swamy@gmail.com’s picture

@hass Could you please review the patch in comment#23?

selva.swamy@gmail.com’s picture

Updated patch with length limited to 40 characters.

relim’s picture

Version: 8.x-2.x-dev » 8.x-3.x-dev
FileSize
2.59 KB

Rerolled patch to work with 3.x branch

Anybody’s picture

Status: Needs review » Needs work

Could someone please prepare this as MR for 8.x-3.x and 4.x for easier review and merge?