![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
|
|
#1 |
|
Newbie
Join Date: Aug 2006
Posts: 20
Rep Power: 0
![]() |
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. |
|
|
|
|
|
#2 |
|
Expert Programmer
|
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.
|
|
|
|
|
|
#3 |
|
Programmer
Join Date: Mar 2007
Posts: 39
Rep Power: 0
![]() |
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. |
|
|
|
|
|
#4 | |
|
Expert Programmer
|
Quote:
|
|
|
|
|
|
|
#5 |
|
Programmer
Join Date: Mar 2007
Posts: 33
Rep Power: 0
![]() |
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. |
|
|
|
|
|
#6 | |
|
Professional Programmer
Join Date: May 2006
Location: UK - London
Posts: 329
Rep Power: 3
![]() |
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:
|
|
|
|
|
|
|
#7 |
|
Newbie
Join Date: Aug 2006
Posts: 20
Rep Power: 0
![]() |
Thanks I was thinking about that too but I wanted to try and accomplish it with as few pages as possible.
|
|
|
|
|
|
#8 |
|
Programmer
Join Date: Mar 2007
Posts: 39
Rep Power: 0
![]() |
Not only that, but they could hit the back button and resubmit the form data on the transfer page.
|
|
|
|
|
|
#9 |
|
King of Portal
|
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'])){
... display the table with its updated database values
... display a URL link to the same page but with the submission form
}else{
... display the table
... display the submission form whose action method should go to the same page but appended with '?foo=1'
}
__________________
Lo, there do I see my father. 'Lo, there do I see My mother, and my sisters, and my brothers. 'Lo, there do I see The line of my people... Back to the beginning. 'Lo, they do call to me. They bid me take my place among them. In the halls of Valhalla... Where the brave... May live... ...forever.. GrimBB | Mimesis |
|
|
|
|
|
#10 |
|
Programmer
Join Date: Mar 2007
Posts: 39
Rep Power: 0
![]() |
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] |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| FFT DWTIB -> Optimization -> Choosing An Appropriate Run Time | Sane | Software Design and Algorithms | 7 | Dec 1st, 2006 10:40 AM |
| Show or hiding forms/modifying control properties ..from different a form.. | cloud- | C# | 4 | Nov 10th, 2006 10:51 AM |
| Form Submit Blues | MegaArcon | Python | 3 | Dec 14th, 2005 4:20 PM |
| .NET Timer Form closing issue | MBirchmeier | C# | 4 | Nov 21st, 2005 10:00 AM |
| entering data into excel from a form | glevine | Perl | 1 | Nov 18th, 2005 5:03 PM |