Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I stop a form being submitted twice ?

Status
Not open for further replies.

towser

Programmer
Feb 19, 2001
29
GB
I have a problem where a users are submitting a form more than once and this is then sending duplicate messages to my back end system.

Is there a way I can trap and subsequently stop the form being submitted twice ?

P.S I don't want to disable the submit button and they also have a requirement to submit the form using the enter key.

Thanks, any pointers would be great
 
The best way to do this would be to trap it server-side. This would also then work where users have JavaScript disabled.

One way to do it would be to deliver a unique key to the page, and test to see if that key has already been submitted. I'm sure you could find a way of doing it with sessions, too. I'd ask in the forum for the server-side technology you are using on how to do this.

Hope this helps,
Dan



[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Cheers Dan. Unfortuately the webpages are being displayed on the fly from an XML message passed back to webserver from a mainframe via an XSLT transformation, so I was kinda hoping they'd be a simple Javascript solution.

I'll look into that anyway though.
 
If you must do this client-side, then try this:

Code:
<script type="text/javascript">
var submittedFlag = false;

function submitForm() {
   if (!submittedFlag) {
      submittedFlag = true;
      return(true);
   }
   return(false);
}
</script>
...

<form onsubmit="return(submitForm());">

Hope this helps,
Dan


[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
You could also just disable the submit button when the form is submitted.

Tracy Dryden

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard. [dragon]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top