Prevent form re submitting?

What is the best way to prevent people from submitting a form?

preventDefault(); E.g. on the form submit, do that.
http://codepen.io/ryanreese09/pen/PqKmoZ

ok, thaniks

Note that any JavaScript solution will only work in browsers when JavaScript is enabled. There would be nothing to stop someone turning JavaScript off in order to submit the same thing a second time. So it depends on the reason why you want to prevent duplicate submission as to whether this would be effective.

There are few cases where duplicate submissions can cause harm as updating a record with the same values twice will have the same result as updating it once and inserting or deleting twice will normally result in the second one failing as the record to be inserted already exists or the one to be deleted can’t be found.

In other situations the safest way is to detect the duplicate submission on the server and action it appropriately there

For what purpose are you wanting to prevent them from submitting a form?

If you want something that doesn’t require JS on the user’s end, I’ve written in a time+random token that was generated on the form page and stored on the submission side. If the token already exists in the database(or flatfile), it quietly ignores the known resubmit.

I just wanted to prevent resubmitts, but I got it.
Thankls

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.