Forum Moderators: coopster

Message Too Old, No Replies

$_POST refresh problem

refresh $_post clear

         

kyler

3:48 pm on Feb 18, 2005 (gmt 0)

10+ Year Member



Hi,

I have a file with a form that call itself and processes the form info.

when my first subbmition is complete I am shown the form again.

If I hit the browser refresh it will add the same info again.... meaning it is keeping the last post in memory.

How can I clear the last post befor the form is shown again

mincklerstraat

4:56 pm on Feb 18, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



you could try the form element:
<input type="reset" />
- see here [w3.org] -

or you could try doing something like making a link to reset it:

echo '<a href="'.$_SERVER['REQUEST_URI'].'">reset</a>';

Is this what you mean?

hakre

5:33 pm on Feb 18, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If I hit the browser refresh it will add the same info again.... meaning it is keeping the last post in memory.

How can I clear the last post befor the form is shown again


that's a bit tricky. normally the browser will ask the user, if the old POSTDATA should be send again (that's what you mean by keeping in memory). the only way to prevent that i know is to tell the browser to redirect immediatly after the post request. that way calling the same form again, the browser will not ask on reload to send postdata again.

kyler

5:43 pm on Feb 18, 2005 (gmt 0)

10+ Year Member



Hi, there

I am looking to reset the post automaticly within my php code not in the form. Meaning that after the form is submitted the php processes this form and distroys the post right them befor the form is re-shown

kyle
The questionaire

hakre

5:47 pm on Feb 18, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



hmm. for me it's not clear what you mean. because the http protokol (that's what used to "post") is stateless, there is only one request containing the postdata. if there is another request containing exact the same postdata, php can do nothing about that.

if you only don't want php to display the values submitted, just don't put the vars in your code, use

value=""
instead.

frizhard

6:21 pm on Feb 18, 2005 (gmt 0)

10+ Year Member



After you do a POST request, browsers keep that information in memory in case they can send it again if you refresh the page. In your case you come from a POST request, so the browser will ask you if you want to send the POST data again, and you cant avoid that.

To prevent this from happening, you could reload the page after you process the POST data, so you have a clean GET request. You can do that with Javascript in the onload event of the body.

I'm not sure if this is your problem, but hope this can help you.

hakre

8:41 pm on Feb 18, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



two files: form.php and post.php

form.php

<form method="post" action="post.php">
<input name="test" value="" />
<input type="submit" />
</form>

post.php

<? /*
* process whatever you want here but don't make any output! *
*/
header("Location: http://host/form.php");
exit();
?>

this is doing a redirect after submission. it won't need javascript and works with any browser. if this does not solve your problem, please describe more specific what you mean.

tata668

9:02 pm on Feb 18, 2005 (gmt 0)

10+ Year Member



I do something similar but my processing of the POST data is done in form.php

post.php puts the POST data in session and redirect:

$_SESSION["POSTDATA"] = $_POST ;
header("Location: [host...]
exit();

Then in form.php:
if(isset($_SESSION["POSTDATA"]))
{
$_POST = $_SESSION["POSTDATA"] ;
unset($_SESSION["POSTDATA"]) ;
}

Each page contains its own POST processing..

My code is more complexe than that but you have the general idea.