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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

disable user from going back after submitting form

Status
Not open for further replies.

akaballa123

Technical User
Apr 29, 2008
46
US
hi..

I created a form using php server and javascript client side. Once the user submits the form, if they click the back button then clicks the submit button again, the form gets re submitted. I do not want to do this. I would like to disable ( idea of atleast) the brower's back button so that once the form is submitted, the user cannot go back to the previous form page with all the values. Is there a way to do this?

Thanks!
 
No. You cannot disable the browser back button.

If the user decides to press the back button and then press the submit button... then it's their choice. It's certainly not usual user behaviour.

You can handle the double submit server-side (and just ignore their subsequent submits) using some simple (non javascript) code (such as a unique string in a hidden form field - and if that is received more than once, you can ignore the submit).

A javascript solution is as simple as setting the disabled property on the submit button (so it cannot be clicked again) just before the form itself is submitted.

Another javascript solution would involve testing for an undefined value on a javascript variable (global - on the window object) when the submit button is clicked. If the variable is undefined then the submit happens and the variable is set. If it is subsequently pressed, then the submit would not be allowed through because the variable was no longer undefined.

You could go with an expiring page with a no-cache directive sent in the headers.

Cheers,
Jeff

[tt]Jeff's Blog [!]@[/!] CodeRambler
[/tt]

Make sure your web page and css validates properly against the doctype you have chosen - before you attempt to debug a problem!

FAQ216-6094
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top