By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,744 Members | 1,835 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,744 IT Pros & Developers. It's quick & easy.

How do I keep from reprocessing forms?

P: n/a
This is my problem.

I want to submit a form to another page to process the data from said form.
Then the person can go on to another part of the site or another site
altogether. However If the person later clicks the <back button> enough
times they will arrive back at the page that processed the data the first
time and the same data will be processed again. How can I prevent this?
My first thought was to use a cookie and set it on submit of the form but I
have not been able to get that to work. Any suggestions?
-Alex
Jul 17 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
I'm just getting into this, but I understand the following should work:

calling page:
....
<form method="POST" action="page2.php">
....
<input type="text" name="searchtext" size="50">
<input type="submit" value="search">
</form>
....

Page you don't want to reprocess (page2.php):
....
$searchtext = $_POST[searchtext];
if (isset($searchtext))
{
unset ($searchtest);
... do everything else...
}

"Alex Thomas" <al*********@mindspring.com> wrote in message
news:pi*****************@newsread2.news.atl.earthl ink.net...
This is my problem.

I want to submit a form to another page to process the data from said form. Then the person can go on to another part of the site or another site
altogether. However If the person later clicks the <back button> enough
times they will arrive back at the page that processed the data the first
time and the same data will be processed again. How can I prevent this?
My first thought was to use a cookie and set it on submit of the form but I have not been able to get that to work. Any suggestions?
-Alex

Jul 17 '05 #2

P: n/a

On 26-Oct-2003, "Jenkins" <ne**@djenkins.nu> wrote:

"Alex Thomas" <al*********@mindspring.com> wrote in message
news:pi*****************@newsread2.news.atl.earthl ink.net...
This is my problem.

I want to submit a form to another page to process the data from said

form.
Then the person can go on to another part of the site or another site
altogether. However If the person later clicks the <back button>
enough
times they will arrive back at the page that processed the data the
first
time and the same data will be processed again. How can I prevent
this?
My first thought was to use a cookie and set it on submit of the form
but

I
have not been able to get that to work. Any suggestions?

I'm just getting into this, but I understand the following should work:

calling page:
...
<form method="POST" action="page2.php">
...
<input type="text" name="searchtext" size="50">
<input type="submit" value="search">
</form>
...

Page you don't want to reprocess (page2.php):
...
$searchtext = $_POST[searchtext];
if (isset($searchtext))
{
unset ($searchtest);
... do everything else...
}

Sorry, this won't work because reprocessing page2.php will repost the form
fields.

AFAIK the only way to avoid the refresh/back problem is to use a session
variable to keep track of what's been posted and refuse the repost.
--
Tom Thackrey
www.creative-light.com
tom (at) creative (dash) light (dot) com
do NOT send email to ja*********@willglen.net (it's reserved for spammers)
Jul 17 '05 #3

P: n/a
One possibility would be to check if this user has posted data already
and ignore it if he/she has.
This is simple if you are taking form data and placing it inside of a
database. Not so simple if something else is being done... i.e. An
customer service email script.
I have a site, where users can purchase items. To do so they have to
fill in a signup form. Obivously we only want each user to have one
account, but double clicking submit would normally create a new
account for them, so here is what I do.

I check the "critical information" against the database, if it exists
I just ignore the input. It looks something like this.

$critical_info = $_POST['email'];

$query = "SELECT * from mytable WHERE email ='$critical_info'";
$result = mysql_query($query);

if(!$result){
//Do whatever it is I need to do to sign this customer up

}else{
echo <<< EOF
Sorry but it appears you've already signed up!<br>
<a href= "mysite.com/lostpass.php">Click here to retrieve your
password</a><br>
EOF;
}

So basically, if you are storing the information, just check to see if
you already have the information before accepting it. If yes ignore,
otherwise store.

I hope this helps.

"Alex Thomas" <al*********@mindspring.com> wrote in message news:<pi*****************@newsread2.news.atl.earth link.net>...
This is my problem.

I want to submit a form to another page to process the data from said form.
Then the person can go on to another part of the site or another site
altogether. However If the person later clicks the <back button> enough
times they will arrive back at the page that processed the data the first
time and the same data will be processed again. How can I prevent this?
My first thought was to use a cookie and set it on submit of the form but I
have not been able to get that to work. Any suggestions?
-Alex

Jul 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.