Problem/Motivation

Follow-up issue to https://www.drupal.org/project/turnstile/issues/3330710 and to https://www.drupal.org/project/turnstile/issues/3505942

When loaded through Drupal dialog and with a challenge already in the page, the js command is not thrown.
I think the detection in TurnstileAjaxSubscriber is not correct / covering all use cases.

Turnstile js files are loaded, but the challenge is not rendered.

Steps to reproduce

  • Install Turnstile
  • Add a form on a region (bottom form in my case)
  • Add a link to open a webform on a dialog
  • Turnstile is not loaded/challenged (and throw an error when submitting "The answer you entered for the CAPTCHA was not correct.")

Proposed resolution

Change onResponse Turnstile detection to cover all response with turnstile library.

<?php
  public function onResponse(ResponseEvent $event): void {
    $response = $event->getResponse();
    if ($response instanceof AjaxResponse) {
      $attachments = $response->getAttachments();
      if (!empty($attachments) && isset($attachments['library']) && !empty($attachments['library']) && in_array('turnstile/turnstile.remote', $attachments['library'])) {
        $response->addCommand(new BaseCommand('turnstileRender', []));
      }
    }
  }
?>

Issue fork turnstile-3529743

Command icon Show commands

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

nicodh created an issue. See original summary.

  • greatmatter committed 103d7407 on 1.1.x
    Add patch from issue #3529743 by @nicodh to resolve AJAX loading problem...
greatmatter’s picture

Status: Active » Needs review

Thanks, @nicodh! I've committed this to dev; I'd like to see it tested in multiple environments before giving it a release tag. None of our sites use it in this manner, so I don't have a good test for it.

filipnest’s picture

Hi! We have a site that this is very much needed on and confirming the patch worked there. Not a modal but loading the form in via ajax when another non ajax form with it on was already on the page.

greatmatter’s picture

Status: Needs review » Fixed

Ok, we've released it.

greatmatter’s picture

Status: Fixed » Closed (fixed)