|
Posted by tmax on 02/14/06 22:18
Well, I've tried everything that has been suggested so far - thanks for
everyone's input.
However, let me restate the problems differently as I believe it wasn't
correct to begin with.
I have a file: index.php
index.php contains a form, which when submitted for processing, calls
itself using <form method="POST" action="{$_SERVER['PHP_SELF']}">
When the form is submitted and index.php is reevaluated, I have the
following IF statement: (FYI: 'submit' is the name of the submit button.)
------------
IF ( !isset($_POST['submit']) ) {
// The form has NOT been SUBMITTED - display the form
echo <<<htmloutput
<form method="POST" action="{$_SERVER['PHP_SELF']}">
...
</form>
htmloutput;
} ELSE {
// The form was SUBMITTED - process the form
process the form data, etc. and print in PLACE of the form the
following:
echo "Information submitted... Thank you.";
}
-------------
I understand I can redirect to a (different) summary page, but all I
want to do is replace the form with the summary message. The problem
comes into being when, after the summary message is displayed, the user
goes to refresh the browser. The browser is still caching the form data
for resubmission. I've tried things like: unset($_POST) or
unset($_POST['submit']) (and all the other form fields) but that has no
affect.
Any other suggestions?
Thanks in advance.
d wrote:
> "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.
>
>
> In the script to which the form submits, store the $_POST data somewhere
> else, say a session. Then, use this:
>
> header("Location: http://host/path/to/script.php");
> exit();
>
> to bounce the user to another page. Most browsers know to not re-submit the
> post data to this new page. The new script can even be the originating
> one - as long as you use the location: header, you'll be fine. You can then
> access the submitted data wherever you stored it.
>
> PS. if you're using a session to store the data, call session_write_close()
> before the header() call, otherwise nasty things happen on some browsers.
>
> dave
>
>
[Back to original message]
|