Every form in Drupal has the problem where a user can click Submit two times, triggering two form submissions (entity saves, etc),
This is especially problematic on checkout though, cause submitting the Review step places the order, sends emails, creates payments. That needs to happen only once.
So, we want a bit of JS that attaches itself to a submit button and disables it when it's clicked.
We at least need to attach it to "edit-actions-next" on checkout, but it's worth investigating whether we can do this for every submit button on checkout, and maybe even other commerce pages (such as cart/)
Related D7 module: https://www.drupal.org/project/hide_submit
Comments
Comment #2
bojanz commentedCommerce 1.x version: https://github.com/drupalcommerce/commerce/blob/7.x-1.x/modules/checkout...
There's also a throbber added via CSS in https://github.com/drupalcommerce/commerce/blob/7.x-1.x/modules/checkout...
However, I don't see a reason to duplicate the submit button when we can just disable it.
This code is from 2010 so it might be working around a long gone browser bug. Will ask Ryan if he remembers.
Comment #3
sumanthkumarc commented@bojanz i just found something in core/misc/form.js , where there is js code to prevent identical submissions twice?? doesn't this help us??
Comment #4
nicola85 commentedComment #5
chrisrockwell commentedThis has caused me a few late night headaches :D. If a customer clicks "Pay and Complete Purchase" 2x the order gets the payment, but it never gets moved to Fulfillment/Complete state, presumably because Auth.net, only seconds after the first payment, throws back an error, leaving the order in Draft status.
I'm attaching an alternative patch that adds the dependency to our commerce_checkout/form library as that's already attached to the forms. Another alternative is to roll just that function into Commerce, as I don't know hat impact these other behaviors will have.
Comment #6
subhojit777Confirmed. The patch is working. However this patch does not works with Commerce Authorize.net accept.js https://www.drupal.org/project/commerce_authnet/issues/2813401. But that is okay.
commmerce_authnet.accept.form.jshandles the payment form submission in a different way.Comment #8
subhojit777Comment #9
subhojit777I cloned the latest version of commerce, and the patch cleanly applied.
Comment #11
bojanz commentedTested with the example gateway and with Braintree. Committed #5. Thanks, everyone! A great team effort.