- Issue created by @cosmicdreams
- Status changed to Postponed: needs info
over 1 year ago 7:12am 25 July 2023 - 🇵🇱Poland sandboxpl Poland 🇵🇱
Hi @cosmicdreams,
by default we try to overrideDrupal.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.