- Issue created by @s_castro
- last update
over 1 year ago 1 pass - πΊπ¦Ukraine dench0
@s_castro
It looks like the problem is not in the module but with the captcha "cacheable" feature.
On Ajax call it should work like this: it validates the reCAPTCHA v3 response and if validation passes, then the captcha element is not added to the returned form at all.Can you pls check this:
1. Set Math as a fallback challenge.
2. Disable "Cacheable" in the reCAPTCHA v3 settings. - π¨π΄Colombia s_castro
@dench0,
Thanks for the quick response.
I tested it again following your recommendation. I already had the "cacheable" checkbox disabled, but it worked when I changed the fallback challenge from reCAPTCHA to Math. For some reason adding reCAPTCHA as the fallback challenge makes the functionrecaptcha_v3_validate
execute multiple times, while the Math executes the function just once (the first time an Ajax element is triggered).Do you know with this is only a problem with reCAPTCHA as fallback challenge?
In both cases, the validation function is executed the first time an Ajax element is triggered instead of being called on the form submit. I am not sure if this is the expected behavior.
- πΊπ¦Ukraine dench0
The reCAPTCHA module not working very well with Ajax forms due to the enabled cacheable feature.
You can verify this by using directly the reCAPTCHA captcha for your form: solve the reCAPTCHA and hit that Ajax button. Depending on what your Ajax callback returns (the entire form or only part of the form) you can get one of two cases:
- The new unsolved reCAPTCHA element.
- reCAPTCHA element stays solved but you will get a captcha error on the form submission.
I think you can discover reCAPTCHA issues for a possible solution (or create a new one if any exists). Or you can solve it by yourself: in
hook_form_alter
you need to unset or set to false reCAPTCHA cacheable: https://git.drupalcode.org/project/recaptcha/-/blob/8.x-3.x/recaptcha.mo....I'll try to solve this on the reCAPTCHA V3 side, but only for the 2.0 version.
- π¨π΄Colombia s_castro
Thanks for your help. It seems to be an issue with the reCaptcha module. Disabling the cacheable feature in a
hook_form_alter
worked for me. - πΊπ¦Ukraine dench0
I have created a patch to move the cacheable property to the "action" entity. Then in the element process hook, it overwrites the fallback challenge "captcha_cacheable" by the action cacheable property.
But then changed my mind and don't think it was a good idea.I left the patch file here just in case.
- Status changed to Closed: works as designed
over 1 year ago 7:43am 29 June 2023 - πΊπ¦Ukraine dench0
Close this issue as the problem is not in the reCAPTCHA v3, but in the reCAPTCHA module.