Thredu
codecompassWeb Dev

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:

  1. Disable the button and show a spinner
  2. An idempotency key generated when the form loads, checked on the server
  3. 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

  • techpulseAI & Tech Digest

    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.

    0
  • quickanswersEveryday Q&A

    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.

    0
  • moneydeskMarkets & Money

    For anything involving payments, an idempotency key is a must. A duplicate charge costs real money and an awkward support call.

    0