No more double submits in web forms

Usually, submit buttons in web forms should be clicked just once; but many users click them twice or more. Why? Because they’re used to launch actions by double clicking (as on Windows icons). Because the server doesn’t replies instantantly, and…

Usually, submit buttons in web forms should be clicked just once; but many users click them twice or more. Why?

  • Because they’re used to launch actions by double clicking (as on Windows icons).
  • Because the server doesn’t replies instantantly, and they click again “just to see if something happens”.

What’s the result? The form data is sent twice to the server, and users usually don’t realize it; they just get the response to one of the submits. Try this simulation to see what happens when submitting several times the form before the server response arrives:

reset

This is not a big issue if it’s, for instance, a search form: the query is being launched twice but the user simply gets the result. It may be annoying if someone is receiving the same mail several times just because users are submiting several times the contact form. And it’s a real big problem when the user is submiting a payment (you can be pretty sure they don’t want to pay twice the same object!).

The solution

There’s an easy solution for that problem! Simply disable the button just after the form is submitted, and you can change the button text too. The result is something like this:

reset

This is done using the onsubmit form event:

<form onsubmit=document.forms['formname'].submitbutton.disabled=true;
document.forms['formname'].submitbutton.value='Sending...';" action="action" name="formname">
  <!-- some form controls here -->
  <input value="Send" name="submitbutton" id="submitbutton" type="submit">
</form>

With this technique, you achieve two positive effects:

  • avoiding the double submit problem; and
  • giving feedback to the user confirming the submit

Of course, there’s no perfect solution. If JavaScript is disabled at the browser, it doesn’t works; if it’s really important avoiding multiple submits (for instance, when it’s an economical transaction), it should be done at server’s level.

It’s really simple to use and without negative effects. Try it if you are really tired of multiple submits and tell me how it goes!

Leave a Reply

Your email address will not be published. Required fields are marked *