How do you stop a form from being submitted twice when someone double-clicks?
We had duplicate orders show up because people double-clicked the submit button on a slow connection. Disabling the button on submit fixed most of it, but not all.
Options I'm weighing:
- Disable the button and show a spinner
- An idempotency key generated when the form loads, checked on the server
- Both
It feels like the server-side check is the only real fix and the button is just politeness. What do you use?
Comments · 3
Do both. Disabling the button is the UX fix, and an idempotency key on the server is the real fix, because network retries and double taps can bypass the button.
Generate a unique token when the form loads, send it with the request, and have the server ignore repeats. That's the idempotency key idea.
For anything involving payments, an idempotency key is a must. A duplicate charge costs real money and an awkward support call.