Image captcha and webform display 2 reload buttons

Created on 2 August 2023, almost 2 years ago
Updated 4 August 2023, almost 2 years ago

Problem/Motivation

After captcha upgrade to the latest 1.13 version (from 1.9v) there are 2 refresh buttons

Steps to reproduce

Using Drupal 9.5, PHP 8.1:

  • Install latest captcha 8.x-1.x (aka version 1.10 just before the branch sync with 2.x).
  • Install latest webform (6.1.5 as of this writing).
  • Add a image captcha element to the standard "Contacts" webform.
  • Go to the webform -> The Image Captcha works and looks as expected.
  • Switch captcha to 2.x branch (aka 2.0.4 or 8.x-1.13)
  • Run drush cr and drush updb
  • The 2 refresh buttons appear
🐛 Bug report
Status

Closed: works as designed

Version

2.0

Component

Image Captcha (image_captcha)

Created by

🇲🇩Moldova sc_cojocari

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

Comments & Activities

  • Issue created by @sc_cojocari
  • 🇩🇪Germany Anybody Porta Westfalica

    Looks like an AJAX / once issue, I guess.

    Could you please provide steps to reproduce this in a vanilla environment? I wasn't able to reproduce this, what ever I tried. Anything special about where the CAPTCHA is placed? Does that happen on any form?

  • 🇲🇩Moldova sc_cojocari

    I have the same issue on the any webform where image captcha element is attached.
    I use docker ENV.

  • 🇩🇪Germany Anybody Porta Westfalica

    1.13 is 2.x-dev so I'm changing versions.
    Still I'm not able to reproduce the issue... mhm

  • 🇲🇩Moldova sc_cojocari

    Ok. I have 2 different sites, both of them on Drupal 9
    First one is with Drupal 9.5.9, Webform 6.1.5 and Captcha 1.13
    Second one is with Drupal 9.5.10, Webform 6.1.5 and Captcha 1.13
    I have the same captcha issue on both of them.

  • Assigned to Grevil
  • 🇩🇪Germany Anybody Porta Westfalica

    @Grevil: Could you please try to reproduce this and see if there's a once() issue? (missing once for the reload icon)

  • 🇩🇪Germany Grevil

    I was able to reproduce this! Thanks, @sc_cojocari.

    I adjusted the "Steps to reproduce" section.

  • 🇩🇪Germany Anybody Porta Westfalica

    @Grevil could you please separately try, if it also happens, if just using 2.x, not upgrading from an older version?
    I still think it's a JS once() issue with some kind of AJAX for example.

  • 🇩🇪Germany Grevil

    Yep, it is a general 2.x issue. Got nothing to do with the upgrade path!

  • Status changed to Postponed almost 2 years ago
  • 🇩🇪Germany Grevil

    Not a problem on our side. Webform manually renders the refresh button on their side in "webform/src/Plugin/WebformElement/Captcha.php", line 245 an follows:

        // Add image refresh button to captcha form element.
        // @see image_captcha_after_build_process()
        if ($form_state->getFormObject() instanceof WebformSubmissionForm) {
          $is_image_captcha = FALSE;
          if ($element['#captcha_type'] === 'image_captcha/Image') {
            $is_image_captcha = TRUE;
          }
          elseif ($element['#captcha_type'] === 'default') {
            $default_challenge = \Drupal::service('config.manager')
              ->getConfigFactory()
              ->get('captcha.settings')
              ->get('default_challenge');
            if ($default_challenge === 'image_captcha/Image') {
              $is_image_captcha = TRUE;
            }
          }
          if ($is_image_captcha && isset($element['#captcha_info']['form_id'])) {
            $form_id = $element['#captcha_info']['form_id'];
            $uri = Link::fromTextAndUrl(t('Get new captcha!'),
              new CoreUrl('image_captcha.refresh',
                ['form_id' => $form_id],
                ['attributes' => ['class' => ['reload-captcha']]]
              )
            );
            $element['captcha_widgets']['captcha_refresh'] = [
              '#theme' => 'image_captcha_refresh',
              '#captcha_refresh_link' => $uri,
              '#parents' => array_merge($element['#parents'], ['captcha_widgets']),
            ];
          }
        }
    

    I'll create an issue with an appropriate MR on their side.

  • Status changed to Closed: works as designed almost 2 years ago
  • 🇩🇪Germany Grevil

    Ok, this was already fixed in webform through 📌 Remove special image_captcha_refresh handling Fixed . But there is no tagged release yet.

    @sc_cojocari please use the webform dev version for the time being.

Production build 0.71.5 2024