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

Preventing POST Again When User Clicks Back Button

P: n/a
I have a number of forms that do significant work based on variables
POSTed from the form. What is the common method of detecting and
preventing this work from being done when the form is POSTed as the
result of the user clicking the Back or Reload buttons in the browser?

--Bruce
Jul 17 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
"Bruce" <bv***************@mailblocks.com> wrote in message
news:3t********************************@4ax.com...
I have a number of forms that do significant work based on variables
POSTed from the form. What is the common method of detecting and
preventing this work from being done when the form is POSTed as the
result of the user clicking the Back or Reload buttons in the browser?

--Bruce


You could give it a form action of, say, "formhandler.php". On
formhandler.php, handle the information from the form (naturally), then send
the user via header("Location: ...") to "success.php", which displays some
message like "The data was successfully submitted." The back button will
then send them to the original form, and the refresh button will just
refresh the success message. Either way, the form won't be re-POSTed.

If the data from the form needs to be immediately displayed, then save the
data from formhandler.php into $_SESSION variables and send a location
header to your display page.

- JP
Jul 17 '05 #2

P: n/a
I guess the problem occurs when I need to display the same page again,
like when I delete a line item in a list of items, or click on a link
to send a stock e-mail to someone.

--Bruce

On Sat, 04 Sep 2004 23:45:32 GMT, "kingofkolt"
<je**********@comcast.net> wrote:
"Bruce" <bv***************@mailblocks.com> wrote in message
news:3t********************************@4ax.com.. .
I have a number of forms that do significant work based on variables
POSTed from the form. What is the common method of detecting and
preventing this work from being done when the form is POSTed as the
result of the user clicking the Back or Reload buttons in the browser?

--Bruce


You could give it a form action of, say, "formhandler.php". On
formhandler.php, handle the information from the form (naturally), then send
the user via header("Location: ...") to "success.php", which displays some
message like "The data was successfully submitted." The back button will
then send them to the original form, and the refresh button will just
refresh the success message. Either way, the form won't be re-POSTed.

If the data from the form needs to be immediately displayed, then save the
data from formhandler.php into $_SESSION variables and send a location
header to your display page.

- JP


Jul 17 '05 #3

P: n/a
"Bruce" <bv***************@mailblocks.com> wrote in message
news:0f********************************@4ax.com...
I guess the problem occurs when I need to display the same page again,
like when I delete a line item in a list of items, or click on a link
to send a stock e-mail to someone.

--Bruce

On Sat, 04 Sep 2004 23:45:32 GMT, "kingofkolt"
<je**********@comcast.net> wrote:
"Bruce" <bv***************@mailblocks.com> wrote in message
news:3t********************************@4ax.com.. .
I have a number of forms that do significant work based on variables
POSTed from the form. What is the common method of detecting and
preventing this work from being done when the form is POSTed as the
result of the user clicking the Back or Reload buttons in the browser?

--Bruce


You could give it a form action of, say, "formhandler.php". On
formhandler.php, handle the information from the form (naturally), then sendthe user via header("Location: ...") to "success.php", which displays somemessage like "The data was successfully submitted." The back button will
then send them to the original form, and the refresh button will just
refresh the success message. Either way, the form won't be re-POSTed.

If the data from the form needs to be immediately displayed, then save thedata from formhandler.php into $_SESSION variables and send a location
header to your display page.

- JP


In that case (if I understand your problem), you can still use the same form
action ("formhandler.php"), and from there, header() the user back to the
original page s/he was viewing. The page will then be updated with the new
(or deleted) records.

- JP
Jul 17 '05 #4

P: n/a
"Bruce" <bv***************@mailblocks.com> wrote in message
news:0f********************************@4ax.com...
I guess the problem occurs when I need to display the same page again,
like when I delete a line item in a list of items, or click on a link
to send a stock e-mail to someone.

--Bruce

On Sat, 04 Sep 2004 23:45:32 GMT, "kingofkolt"
<je**********@comcast.net> wrote:
"Bruce" <bv***************@mailblocks.com> wrote in message
news:3t********************************@4ax.com.. .
I have a number of forms that do significant work based on variables
POSTed from the form. What is the common method of detecting and
preventing this work from being done when the form is POSTed as the
result of the user clicking the Back or Reload buttons in the browser?

--Bruce


You could give it a form action of, say, "formhandler.php". On
formhandler.php, handle the information from the form (naturally), then sendthe user via header("Location: ...") to "success.php", which displays somemessage like "The data was successfully submitted." The back button will
then send them to the original form, and the refresh button will just
refresh the success message. Either way, the form won't be re-POSTed.

If the data from the form needs to be immediately displayed, then save thedata from formhandler.php into $_SESSION variables and send a location
header to your display page.

- JP


In that case (if I understand your problem), you can still use the same form
action ("formhandler.php"), and from there, header() the user back to the
original page s/he was viewing. The page will then be updated with the new
(or deleted) records.

- JP
Jul 17 '05 #5

P: n/a
Hello,

On 09/04/2004 08:27 PM, Bruce wrote:
I have a number of forms that do significant work based on variables
POSTed from the form. What is the common method of detecting and
preventing this work from being done when the form is POSTed as the
result of the user clicking the Back or Reload buttons in the browser?


You may want to try this class that lets you specify a message that
appears on alert box when the users tries to submit the same form again.
It does not stop an user from submitting the same form again if he
really wants, but it prevents that many nervous users submit the same
form again by accident, which in my experience happens quite often:

http://www.phpclasses.org/formsgeneration
--

Regards,
Manuel Lemos

PHP Classes - Free ready to use OOP components written in PHP
http://www.phpclasses.org/

PHP Reviews - Reviews of PHP books and other products
http://www.phpclasses.org/reviews/

Metastorage - Data object relational mapping layer generator
http://www.meta-language.net/metastorage.html
Jul 17 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.