By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,949 Members | 1,855 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,949 IT Pros & Developers. It's quick & easy.

About 'resend form information' when i hit 'BACK' button

P: 16
Hi, guys

sorry if this kind of question had been asked before and kinda newbie question. coz i'm new to programming and just couldn't figure it out yet...

My problem is:

I have a form that POST variables and execute function in the target page (That function happens to be sending email).
If i hit the back button, the browser asks me if i'd resend the information again. And thus, the email would be sent again.

My question is:

Is there any best practice or some kind of techniques to overcome this tipical problem? Coz i know disabling the BACK button would be very bad idea and i don't like it either.

I tried to capture the isset(POST['submit']) parameter so that the code would only executed if i ACTUALLY hit the SUBMIT button.

But, apparently, the BACK button is somekind like 're-doing' my actions (as if i was actually hit the submit button)

I tried the history.go(1) techniques, but it only works in IE. I want it works for cross browsers.

Thanks alot...
Oct 20 '08 #1
Share this Question
Share on Google+
5 Replies

Expert 100+
P: 1,208
There is a way to do this if I remember correctly you do it as follows
page a -> post to pageb -> transfers you to pagec without writing anything
and in this method when you hit back it goes from pagec to pagea.. and doesn't want to retransmit the data.
Oct 20 '08 #2

Expert 5K+
P: 5,058
I was working on a similar problem the other day.

What I did was create a random string (a hash), which I stored in a session variable and echoed into a hidden <input> element in my form page.

Then, once the data had been submitted, I had my action page match the session variable to the value of the <input> element. If they matched, I unset the session variable and processed the form. If they didn't I simply redirected the user back to the form page.

This only allows each form to be submitted once, requiring a new random string for each submission.
Oct 20 '08 #3

P: 16
Thanks Clint and Atli,

You've been really helpful. Now i have a slight idea about how to do it. I'll try your suggestion.

Oct 21 '08 #4

P: 16
wow, thanks Clint and Atli,

I tried your suggestion, i make random number, store it in session variable, pass it to hidden input element in the action form and in the action page i compare with the POST variable. and it works!

So, if user hit BACK button, it won't be a problem now, coz the session doesn't match with the POST.

Thanks guys...
Oct 21 '08 #5

Expert Mod 15k+
P: 16,027
In case you're interested, the method Clint was referring to is Post/Redirect/Get (PRG).
Oct 24 '08 #6

Post your reply

Sign in to post your reply or Sign up for a free account.