Captcha disappears on Commerce Checkout Panes with Commerce Shipping module

Created on 9 April 2024, about 1 year ago
Updated 10 July 2024, 10 months ago

Problem/Motivation

The captcha disappears when the automatic shipping calculation is triggered.

Steps to reproduce

  1. Add a captcha to the checkout flow by creating a new "Captcha point" for the "commerce_checkout_flow_multistep_default" form
  2. Create an order and go to the order information step
  3. I can see the captcha and it works properly
  4. Enter the shipping address to start the automatic calculation
  5. After the automatic calculation, the captcha disappears

Proposed resolution

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;
    }
๐Ÿ› Bug report
Status

Needs review

Version

2.0

Component

Code

Created by

๐Ÿ‡บ๐Ÿ‡ฆUkraine marchuk.vitaliy Rivne, UA

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024