Fixed
Project:
CAPTCHA
Version:
2.x-dev
Component:
Code
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
9 Apr 2024 at 06:24 UTC
Updated:
2 Nov 2026 at 21:32 UTC
Jump to comment: Most recent, Most recent file
The captcha disappears when the automatic shipping calculation is triggered.
The captcha disappears because the following code runs:
if ($form_state->getTriggeringElement() && isset($form_state->getTriggeringElement()['#limit_validation_errors']) && is_array($form_state->getTriggeringElement()['#limit_validation_errors'])) {
// This is a partial (ajax) submission with limited validation. Do not
// change anything about the captcha element, assume that it will not
// update the captcha element, do not generate anything, which keeps the
// current token intact for the real submission.
return $element;
}
But in the case of automatic recalculation, it should not be run.
We need to improve the conditions to not run this code:
$triggering_element = $form_state->getTriggeringElement();
$recalculate = !empty($triggering_element['#recalculate']);
if ($triggering_element && isset($triggering_element['#limit_validation_errors']) && is_array($triggering_element['#limit_validation_errors']) && !$recalculate) {
// This is a partial (ajax) submission with limited validation. Do not
// change anything about the captcha element, assume that it will not
// update the captcha element, do not generate anything, which keeps the
// current token intact for the real submission.
return $element;
}
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | captcha-fix_commerce_shipping_recalculate_issue-3439550-1.patch | 1.07 KB | vmarchuk |
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
Comment #2
vmarchukWe probably need to add more conditions to check if commerce_shipping is enabled, but here is a patch that fixes the problem.
Comment #5
rajan kumar@2026 commentedHii @vmarchuk
I have successfully applied the above patch #2 and created a merge request. Please review it when you have a chance. Thanks!
Comment #6
joao sausen commentedWe had a similar issue recently and fixed by repositioning the captcha:
Comment #7
leo pitt commentedThe patches here and solutions don't seem to resolve the issue when recaptcha_v3 is being used.
Comment #8
elamanI've created an issue on Commerce Shipping module issue queue, that I will quote below: #3558272: AJAX causes Captcha to loose track of its session
I'm checking this with Math challenge type, but ultimately would be nice to have it working with reCAPTCHAs:
Comment #9
elamanThe #2 patch resolves the issue with challenge type Math. I'm wondering if it will work for reCAPTCHA v3. I've created issue there: #3558274: Any AJAX on the form, causing reCaptcha v3 to immediately fallback to reCaptcha v2 and will explore further.
Comment #10
anybody@vmarchuk could you maybe explain the fix in #2 and add explanations to the code as comments? I don't think this is obvious enough.
What are your further thoughts on the solution?
Comment #12
japerryThe bug is valid and not specific to Commerce: any rebuild triggered by a `#limit_validation_errors` button empties the CAPTCHA. MR !95's `#recalculate` check is a Commerce-only workaround with side effects, so I replaced it with a generic fix and a functional test.
The new approach, for submissions with limited validation:
Comment #15
japerry