Re: How to keep <form> from re-submitting on page refresh...

Re: How to keep <form> from re-submitting on page refresh...

am 31.07.2007 21:48:26 von luiheidsgoeroe

On Tue, 31 Jul 2007 20:49:29 +0200, NoNameNoWhere
wrote:

> I have forms that are handled by PHP scripts in the same file that
> generates the page. After the page regenerates with the results of
> the form submission, a refresh of the page re-submits the values of
> the previous form. Is there a way to reset or clear that form data
> to prevent the re-submission of data?

Most simple solution is often do the thing you want with the posted data
in it on the receiving page (use PHP sessions if the data has to 'live
longer'), and redirect (with a proper HTTP header, not some javascript or
meta thingy) to another (or possibly the same page). Posts are 'lost' on
redirects, so no data will be resubmitted on refresh, the browser will go
straight to the page you provided.

As this is not really an HTML but PHP related issue (well, at least the
solution is), I've taken the liberty to post this answer to that group,
and set the follow-up to it.
--
Rik Wasmus

Re: How to keep <form> from re-submitting on page refresh...

am 02.08.2007 23:20:43 von davidkruger

On Jul 31, 2:48 pm, Rik wrote:
> On Tue, 31 Jul 2007 20:49:29 +0200, NoNameNoWhere
> wrote:
>
> > I have forms that are handled by PHP scripts in the same file that
> > generates the page. After the page regenerates with the results of
> > the form submission, a refresh of the page re-submits the values of
> > the previous form. Is there a way to reset or clear that form data
> > to prevent the re-submission of data?
>
> Most simple solution is often do the thing you want with the posted data
> in it on the receiving page (use PHP sessions if the data has to 'live
> longer'), and redirect (with a proper HTTP header, not some javascript or
> meta thingy) to another (or possibly the same page). Posts are 'lost' on
> redirects, so no data will be resubmitted on refresh, the browser will go
> straight to the page you provided.
>
> As this is not really an HTML but PHP related issue (well, at least the
> solution is), I've taken the liberty to post this answer to that group,
> and set the follow-up to it.
> --
> Rik Wasmus

Thank you for the info, I have a couple of scripts that I have
occasionally had an issue with being double-submitted, if someone did
a refresh. I was just curious however, instead of redirecting to a
new page, or the same page, if using unset would work as well, after
processing the posted form data, either using unset($_POST); or unset
each assigned key in $_POST individually?

Re: How to keep <form> from re-submitting on page refresh...

am 03.08.2007 02:19:54 von Jerry Stuckle

dkruger wrote:
> On Jul 31, 2:48 pm, Rik wrote:
>> On Tue, 31 Jul 2007 20:49:29 +0200, NoNameNoWhere
>> wrote:
>>
>>> I have forms that are handled by PHP scripts in the same file that
>>> generates the page. After the page regenerates with the results of
>>> the form submission, a refresh of the page re-submits the values of
>>> the previous form. Is there a way to reset or clear that form data
>>> to prevent the re-submission of data?
>> Most simple solution is often do the thing you want with the posted data
>> in it on the receiving page (use PHP sessions if the data has to 'live
>> longer'), and redirect (with a proper HTTP header, not some javascript or
>> meta thingy) to another (or possibly the same page). Posts are 'lost' on
>> redirects, so no data will be resubmitted on refresh, the browser will go
>> straight to the page you provided.
>>
>> As this is not really an HTML but PHP related issue (well, at least the
>> solution is), I've taken the liberty to post this answer to that group,
>> and set the follow-up to it.
>> --
>> Rik Wasmus
>
> Thank you for the info, I have a couple of scripts that I have
> occasionally had an issue with being double-submitted, if someone did
> a refresh. I was just curious however, instead of redirecting to a
> new page, or the same page, if using unset would work as well, after
> processing the posted form data, either using unset($_POST); or unset
> each assigned key in $_POST individually?
>

No, If they refresh the page, the post data are sent again.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

Re: How to keep <form> from re-submitting on page refresh...

am 03.08.2007 03:53:15 von Larry Anderson

I have a session array variable that stores the name(ID) of the form
and a time stamp of when the form was created (this ID and time stamp
is POST hidden on the form as well.) If I get a POSTed form I check
the POSTED ID and time stamp with the Session value, if they match it
is a valid update (if the from is valid and action taken I end by
erasing the the session ID/timestamp value.)

If the from POST and session do not match it is an unregistered POST
and automatically headers back to a previous menu.

This saves from errors of opening multiple windows as well as
resubmission when using the back button.

Larry

Re: How to keep <form> from re-submitting on page refresh...

am 03.08.2007 13:13:42 von Michael Fesser

..oO(larry@portcommodore.com)

>This saves from errors of opening multiple windows as well as
>resubmission when using the back button.

It's not only about resubmission. If a page is the result of a POST
request, most (all?) browsers will show a warning if the user uses the
back button to move back to that POST-result page. Usually you'll then
get something like "page expired", either in the window itself or as a
popup. Doing a redirect to the same page after the POST prevents that.

Micha