DelphiFAQ Home Search:

Avoid that a HTML FORM is submitted twice

 

comments3 comments. Current rating: 4 stars (2 votes). Leave comments and/ or rate it.

Question:

What is the best way to make sure a user does not submit a form twice?

Answer:

The easiest way: Disable the submit button in the onclick() event. See the code for that in the box below.

You can also put some code in the form's onsubmit() event, as the second code snippet shows.

<!-- 
  disable the submit button after the first click: 
//-->
<input type="submit" onClick="this.disabled=true">


<!--
  Note: the following goes all in one line. 
  This method sets a 'flag' (this.submitted) to 
  avoid multiple submissions of your form.
//-->

<form action=".." \
 onsubmit="if (this.submitted) return false; \
else { \
this.submitted = true; disableSubmits(this); \
return true;}"

Comments:

2005-12-12, 22:04:54
anonymous from France  
rating
If the user clicks 'back' he opens again the form but it's dead
2006-04-01, 09:39:43
anonymous from India  
goodfix
2008-04-26, 05:53:55
anonymous from Uganda  
rating
Fanatastic

 

 

Email address (not necessary):

Rate as
Hide my email when showing my comment.
Please notify me once a day about new comments on this topic.
Please provide a valid email address if you select this option.
 
It seems that you are
from Washington, US .

Info/ Feedback on this

Show city and country
Show country only
Hide my location
Leave your comment here:
Please type in the code:
photo Add a picture:

Please do not post inappropriate pictures. Inappropriate pictures include pictures of minors and nudity. The owner of this web site reserves the right to delete such material.