Possible racing issue / out-of-order form submission

Created on 24 July 2023, over 1 year ago
Updated 25 June 2024, 6 months ago

Problem/Motivation

I believe I've found a bug with this module in how it handles the ajax form submissions. What I'm experiencing is:

When a simple_recaptcha enabled form submits, the javascript-driven actions do not occur before the backend-driven actions. As a result, the form is not extended to include a simple_recaptcha_token. This leads the form to include the error, There was an error during validation of your form submission, please try to reload the page and submit form again.

Steps to reproduce

  1. Create a custom form
  2. extend simple_recaptcha support to the form
  3. submit the form
  4. Observe error

Proposed resolution

Diagnose if the form can await the response of google's recaptcha logic before moving on to execute remainder of ajaxFormSubmit.

Remaining tasks

User interface changes

API changes

Data model changes

🐛 Bug report
Status

Postponed: needs info

Version

1.0

Component

Code

Created by

🇺🇸United States cosmicdreams Minneapolis/St. Paul

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

Comments & Activities

  • Issue created by @cosmicdreams
  • Status changed to Postponed: needs info over 1 year ago
  • 🇵🇱Poland sandboxpl Poland 🇵🇱

    Hi @cosmicdreams,
    by default we try to override Drupal.Ajax.prototype.beforeSubmit via JS library, this should stop the ajax submit before the module does it's work and populates the token, you can see this here:
    https://git.drupalcode.org/project/simple_recaptcha/-/blob/8.x-1.x/js/si...
    If this doesn't work there might be plenty of reasons for custom forms, could you provide some basic code example for the custom form which does not work for you? We need some steps to reproduce this, maybe if we have an example structure we could provide a test for custom forms as well

  • 🇺🇸United States cosmicdreams Minneapolis/St. Paul

    I believe what I'm seeing is that the form submits twice. Even more strange than that, the form receives an error both times it submits. We don't have a situation where the form submits, then properly gets the simple_recaptcha_token then submits again. Let me see if I can get you a code example.

  • 🇺🇸United States cosmicdreams Minneapolis/St. Paul

    It also appears to only impact forms that already have ajax capabilities built in. I have a form that "adds another" set of fields upon clicking a link. In diagnosing this problem and already "fixing" one my forms. The solution was to remove any extraneous ajax that the form doesn't need. By pruning out the ajax from another form I was able to get the recaptcha support working for it.

  • 🇮🇩Indonesia awset

    I am able to replicate this issue with custom form, it is a combination of custom form and ajax.

    The issue is due to https://git.drupalcode.org/project/simple_recaptcha/-/blob/8.x-1.x/js/si... it always false after ajax success or fail.

    above lead to onclick on the button (line 42) is never executed.

    my work around is by implementing CommandInterface class, the js of that class look like this.

    Drupal.Ajax.prototype.beforeSubmit = function (form_values, element_settings, options) {
          const buttonElement = document.querySelector('.simple-recaptcha-submit');
          if (buttonElement.dataset.disabled === 'true') {
            this.ajaxing = false;
            return false;
          }
    
          return true;
        };
    

    it took me hours to figure it out, for some reason webform is working just fine, so it was leading my investigation to other rabbit hole.

Production build 0.71.5 2024