• Post Reply Bookmark Topic Watch Topic
  • New Topic

how to disable submitting more than once

 
hanumanth reddy
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Hi ALl
How to Disable Submitting More Than once if Imgae is used for
submitting ?.

 
Jeff Sunder
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is a way to do it in JavaScript, if you are using the onClick button. Basically you assign a variable a value of zero and increment the value once the button is clicked. then you run a conditional statement to make sure the var is not greater than 1. Something like this:
var submitCount = 0;
onClick () {
submitCount++;

if (submitCount > 1) {
//do not submit the form
}else{
//submit the form
}
}
 
Steve Snodgrass
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We have used the approach recommened above but ran into the following problems.
1) When the user clicked the Stop button after making the request they basically had to close the browser and restart. Does anyone have a nice fix for this besides capturing the Stop button and resetting the flag?
2) The user can hit the refresh button and resubmit the last request.
We determined that javascript can be helpful in preventing mutliple submits but the situation really needs to be handled on the server.
 
Soft Music
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You might want to try this:
onSubmit='if (this.submitted) return false;
else return somekindjavascriptfunction(this); '
to the <FORM> tag

The javascript file can simply set
this.sumbitted =true;
return true;
or do some edit check first and then set the submitted to true before return true.
So after one successful submission, the subsequent submissions are disabled.
Hope it helps. It did the trick for me.
Soft Music
 
Zakaria Haque
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys, the server side solution is to use teh so called synchronizer token. The basic idea is, you put a hidden field in the form that contains a unique value, and you put this value in session. When the user submits the form, you check the hidden field, if the value is same as in teh session, this is a valid submition. you take off the object from session and process the request. If those two does not match, this is a duplicate submition (or a very late one).
If you need code example, feel free to ask.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!