Welcome to WebmasterWorld Guest from 23.22.220.37

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)

Junior Member

10+ Year Member

joined:Nov 4, 2003
posts:104
votes: 0


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)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Nov 26, 2003
posts:1133
votes: 0


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)

Junior Member

10+ Year Member

joined:Nov 4, 2003
posts:104
votes: 0


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)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Mar 31, 2003
posts:1316
votes: 0


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)

Junior Member

10+ Year Member

joined:Sept 3, 2005
posts:131
votes: 0


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)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Mar 31, 2003
posts:1316
votes: 0


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)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Nov 26, 2003
posts:1133
votes: 0


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