|
Posted by Marc van Lieshout on 02/14/06 23:52
I don't think there is another solution than storing state information
somehwere.
I would use the following method:
1. Before displaying the form, generate some unique number
2. add this number in a hidden field in the form.
3. When the user submits, mark the number as 'used'
4. When the user submits again, ignore the data, because the number
has already been 'used' up.
The simplest way to do this is to create a counter, either in a file on disk
or in
a database. Before you send the form to the client, increment the counter
and send
the counter value in a hidden field in the form.
If you save the form data in a database table, add a 'counter' field to the
table.
When the form is first submitted, a record with the counter value sent with
the form should not exist. Save data and counter.
If the form is submitted for a second or third time, the counter is already
present in
your table, so you should ignore the data in the post.
Using a session cookie is, I think, less work.
"tmax" <tmax@comcast.net> wrote in message
news:8281b$43f21506$481a8e8e$18008@PGTV.COM...
> PHP Pros:
>
> I have a simple html form that submits data to a php script, which
> processes it, and then redisplays the same page, but with a "thank you"
> message in place of the html form. This is all working fine. However,
> when refresh the browser, I get the following message displayed:
>
> "The page you are trying to view contains POSTDATA. If you resend the
> data, any action the form carried out (such as as search or online
> purchse) will be repeated. To resend the data, click OK. Otherwise, click
> Cancel."
>
> Obviously I don't want my users to resend the data to me.
>
> What do I need to do code-wise so that when the browser is refreshed, the
> page is reloaded without this message being displayed.
>
> Thanks in advance.
[Back to original message]
|