Welcome to WebmasterWorld Guest from 54.205.115.177

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

PHP Form keeps resending information on reload.

   
7:18 am on Dec 8, 2006 (gmt 0)

10+ Year Member



Hi,

I have PHP form that is basically a contact page when the user clicks on submit. I have the page update with your message that says it has been sent, but now if the user clicks on reload it ask to resubmit the information over again. And that's where i want to stop this so when the user clicks on reload it will not resubmit the information again. How can this be done?

thanks,
pat

8:44 am on Dec 8, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi Pat!

You can insert redirecting, even to the same page. Then on reload page will be sent without post data.

To redirect you can use

<meta http-equiv="Refresh" content="0;url=<?php echo $HTTP_SERVER_VARS[PHP_SELF];?>">

Regards
Michal

6:32 pm on Dec 8, 2006 (gmt 0)

10+ Year Member



that doesnt seem to work. it just keeps refreshing non-stop. i put it in the < head >
3:26 am on Dec 9, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



After the form data has been handled, use a Location redirection to go to a different page.

header("Location: thank_you.php");

Also, at the very top of the same handling script, say:
ob_start();

That will ensure that the header() works.

11:19 am on Dec 9, 2006 (gmt 0)

5+ Year Member



Hello,

After performing necessary work with coming data you can use unset($_POST) to flush $_POST array.

It may help you.

Vinic

5:01 pm on Dec 9, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Oops, I lied. I use Location redirects on all my forms, but it doesn't prevent the refresh problem.

<meta http-equiv="Refresh" content="0;url=<?php echo $HTTP_SERVER_VARS[PHP_SELF];?>">

This is the answer, but you probably have to redirect to a different page, not the same one.

<meta http-equiv="Refresh" content="0;url=http://site/thank_you.php">

9:55 pm on Dec 12, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



or just redirect when there is POST data:

if(isset($_POST))
{
echo "<meta http-equiv=\"Refresh\" content=\"0;url=".$HTTP_SERVER_VARS[PHP_SELF]."\">";
//... and parse the POST however you like.
}

Hope this helps
Michal