Prevent users to submit HTML form multiple times

Posted By : Shakil Pathan | 30-Sep-2017

Hi Guys,

In this blog, I'm going to explain about why we should prevent users to submit HTML form multiple time simultaneously and how to do it.

Sometimes if the response is slow, the user can click on the submit button several times. While submitting a form, on the backend server, we create entries in our databases. But when a user submits an HTML form multiple times simultaneously then it is likely to create problem in the database because we save the data and the relationships for the submitted data by the user. So there can be multiple solution for this problem. One is, we can handle multiple form submit at beckend server and other one is we can disable the form submit button if the form is already submitted.

Below is a simple code which prevent user to submit form multiple times simultaneously:


 
function validateApplicant(form) { $("saveButtonDiv").style.display="none"; $("processDiv").style.display=""; }

In the above example we are disabling the submit button of form when it submits by the user.

All form validation must be done on the server side. This includes multiple submission checks. Never trust the client! This is not just a case if javascript is disabled. Keep in mind that all client codes can be modified. It is somewhat difficult to imagine, but the html / javascript that is spoken with your server is not necessarily the html / javascript you have written.

Hope it helps!

 

About Author

Author Image
Shakil Pathan

Shakil is an experienced Groovy and Grails developer . He has also worked extensively on developing STB applications using NetGem .

Request for Proposal

Name is required

Comment is required

Sending message..