Problem/Motivation

When Commerce shipping enabled and Captcha + reCaptcha v3 (with recaptcha v3 as fallback) is added two issues occur:
1. When you enter/change ZIP code the variables in `user_input` of a form state for Captcha `captcha_*` are lost, so the form fails validation with a message "The answer you entered for the CAPTCHA was not correct."
2. When you switch the shipping method the reCaptcha v3 immediately falls back to reCaptcha v2, instead of ignoring AJAX request and waiting for proper submit.

I suspect that issue #2 is probably problem with reCaptcha v3 module, however it seems like using AJAX shouldn't cause issue #1 to happen.

Would appreciate some pointers.

Comments

elaman created an issue. See original summary.

jsacksick’s picture

See ShippingInformation::clearValues() perhaps clearing the input values.

elaman’s picture

@jsacksick clearValues() doesn't remove the captcha_* variables from user inputs in the form state.

Commenting out these lines https://git.drupalcode.org/project/commerce_shipping/-/blob/3.x/src/Plug...
make it work.

elaman’s picture

I've switched to included Math captcha type.

What should happen:
- I visit the Order information page.
- I enter ZIP code.
- I enter Captcha Math challenge response.
- I click submit.
- I see payment form.

What is happening:
- I visit the order information page.
- I enter ZIP code.
- I can't enter Captcha Math challenge response, because input disappeared.
- I click submit.
- I'm still on order information page, but with failed validation: Math question (11 + 1 =) field is required.

What is happening when I comment out #limit_validation_errors:
- I visit the order information page.
- I enter ZIP code.
- I immediately see failed validation "Math question (7 + 10 =) field is required."
- I enter Captcha Math challenge response.
- I click submit.
- I see payment form.

elaman’s picture

This might end up being Captcha module issue after all: #3439550: Captcha disappears on Commerce Checkout Panes with Commerce Shipping module. Patch provided there fixes the issue.

elaman’s picture

On the other note, use reCAPTCHA reveals additional issue. When ZIP code is entered and/or shipment method is selected, the whole form is replaced, which forces user who already ticked reCAPTCHA, to have to re-tick it again.

So is it possible to make localized AJAX changes rather than whole form?