Click to See Complete Forum and Search --> : Ensure a FORM is submitted once
rculver
03-13-2003, 02:40 PM
I want to ensure that a user submits a FORM only once. I do not want him to submit the same FORM twice and three times because the user is impatient. How can I do this? Also, I need to have the system recognize when he hits submit and when he hits refresh, because a refresh will re-submit the FORM.
Thanks for all the help I have received previously.
Thanks in advance.
Nedals
03-13-2003, 02:49 PM
You can't really stop multipule submits using Javascript. As you stated, refresh and the back button will set up the page for a new submission. The problem needs to be solved server-side.
Simply ignore the data, if it's already there, and send back a 'you've already posted' page.
requestcode
03-13-2003, 02:50 PM
Here is some sample code that someone gave to me along time ago.
<script language="javaScript">
<!--//
submited=0
function subCheck(){
(submited==0) ? document.f.submit() : window.focus()
submited++
}
//-->
</script>
<form name=f method=post action=http://www.disney.com>
<input type=button value=submit onclick=subCheck()>
</form>
Instead of using an input type of submit you change it to button and then use javascript to submit the form. Of course if you are submitting a form with "mailto" in the action field then this won't work. Also if they refresh this won't work because the variable submited gets reset.
rculver
03-14-2003, 07:52 AM
What does the line (submited == 0) ? document.f.submit() : window.focus() mean. We were taking a look at it yesterday and we were confused by it. Thanks for your reply and also for the reply from nedals.
requestcode
03-14-2003, 08:03 AM
It is a short cut if then else. It is basically saying that if the variable submitted equals zero then submit the document, else place focus on the window. Here is a link to a short explanation on how it works:
http://www.javascriptkit.com/javatutors/varshort5.shtml
Nevermore
03-14-2003, 01:47 PM
Place a cookie on the users system as well when they submit the form, and have it expire after 20 minutes.
Nedals
03-14-2003, 02:32 PM
cijori,
That's a good idea. Hadn't thought of that!! :)