![]() |
How to handle form reloads
Hi,
I have a form that submits data to a script that adds the information to a table and then the script displays the added information on the screen. Now, if the user hits the "Refresh" button on the browser the script is executed again and another record gets added with the same information. I was wondering how to go about handling this issue so that if the user hits "Refresh" the script will not do anything. |
When the user submits the form, return the data with a hidden value. Check for that hidden value when the form is submitted. Then simply don't update the data, just return what was sent.
|
That won't work. The hidden variable will be available for the next page, not the page they submitted. Or if you're talking about it being there from the start, that wont work either, as the hidden variable would be resubmitted as well.
Set a cookie when it's submitted. Then, check if the cookie is set. You could also use sessions, or checking if the submitted data to see if a similar data set is already in the database or was just submitted. |
I always check to see if the database already has a set of matching records, assuming your input contains 1 piece of data that always has to be unique, a username for instance), then use that.
A cookie would also work, BUT, if someone submits then deletes their cookies and refreshes, it would most likely be entered again. |
Why don't you have a page that scripts goes to, this page will update the table(s) then this page will go to another page where you get information from the table and display it. That way if they do decide to refresh only the get data operations will recur.
|
Quote:
|
Not only that, but they could hit the back button and resubmit the form data on the transfer page.
|
Quote:
|
I think Booooze idea would work just fine, for instance here's a sample instead of using a hidden variable using the $_GET superglobal:
:
if(isset($_GET['foo'])){ |
could you give an example perhaps?
Here's what I'm thinking based on this: [php]<?php if (isset($_POST['test']) && $_POST['test'] == 'false') { // process form // to know the difference between whether it was the first submission or // the second submission, you'd have to check something such as the database // otherwise, there's no difference } <form method="post"> <input type="hidden" name="test" value="false"> <input type="submit" name="submit" value="Submit"> </form>[/php] |
| All times are GMT -5. The time now is 2:20 AM. |
Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC