Preventing POST Again When User Clicks Back Button | | |
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 | | | | re: Preventing POST Again When User Clicks Back Button
"Bruce" <bvanderw-news5021@mailblocks.com> wrote in message
news:3thkj0lvms3m8152en2s3pf6guerlvlia7@4ax.com...[color=blue]
> 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[/color]
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 | | | | re: Preventing POST Again When User Clicks Back Button
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"
<jessepNOSPAM@comcast.net> wrote:
[color=blue]
>"Bruce" <bvanderw-news5021@mailblocks.com> wrote in message
>news:3thkj0lvms3m8152en2s3pf6guerlvlia7@4ax.com.. .[color=green]
>> 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[/color]
>
>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
>[/color] | | | | re: Preventing POST Again When User Clicks Back Button
"Bruce" <bvanderw-news5021@mailblocks.com> wrote in message
news:0flkj0trhuaggh7g3lompe3nhqthb04i44@4ax.com...[color=blue]
> 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"
> <jessepNOSPAM@comcast.net> wrote:
>[color=green]
> >"Bruce" <bvanderw-news5021@mailblocks.com> wrote in message
> >news:3thkj0lvms3m8152en2s3pf6guerlvlia7@4ax.com.. .[color=darkred]
> >> 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[/color]
> >
> >You could give it a form action of, say, "formhandler.php". On
> >formhandler.php, handle the information from the form (naturally), then[/color][/color]
send[color=blue][color=green]
> >the user via header("Location: ...") to "success.php", which displays[/color][/color]
some[color=blue][color=green]
> >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[/color][/color]
the[color=blue][color=green]
> >data from formhandler.php into $_SESSION variables and send a location
> >header to your display page.
> >
> >- JP
> >[/color]
>[/color]
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 | | | | re: Preventing POST Again When User Clicks Back Button
"Bruce" <bvanderw-news5021@mailblocks.com> wrote in message
news:0flkj0trhuaggh7g3lompe3nhqthb04i44@4ax.com...[color=blue]
> 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"
> <jessepNOSPAM@comcast.net> wrote:
>[color=green]
> >"Bruce" <bvanderw-news5021@mailblocks.com> wrote in message
> >news:3thkj0lvms3m8152en2s3pf6guerlvlia7@4ax.com.. .[color=darkred]
> >> 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[/color]
> >
> >You could give it a form action of, say, "formhandler.php". On
> >formhandler.php, handle the information from the form (naturally), then[/color][/color]
send[color=blue][color=green]
> >the user via header("Location: ...") to "success.php", which displays[/color][/color]
some[color=blue][color=green]
> >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[/color][/color]
the[color=blue][color=green]
> >data from formhandler.php into $_SESSION variables and send a location
> >header to your display page.
> >
> >- JP
> >[/color]
>[/color]
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 | | | | re: Preventing POST Again When User Clicks Back Button
Hello,
On 09/04/2004 08:27 PM, Bruce wrote:[color=blue]
> 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?[/color]
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 |  | | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 226,537 network members.
|