Saving form contents so that they reappear
Moderator: General Moderators
Saving form contents so that they reappear
Dear All
I'm trying to use sessions to save the contents of a data form, so that when the user goes on to the next page (and the contents are posted), when they press 'back', they reappear so that they can still be edited.
I've tried to do this by setting the post variables derived from the data form equal to its own session variable. Then, when the user presses 'back' to get back to the data form, I have the data form check to see if these session variables are != "", and if so populate the data objects with their previous values.
However, this doesn't seem to work, and the session variables don't seem to be preserved if I press 'back'. Is this normal, and if so, is there a better way of getting this done?
Many thanks
Mark
I'm trying to use sessions to save the contents of a data form, so that when the user goes on to the next page (and the contents are posted), when they press 'back', they reappear so that they can still be edited.
I've tried to do this by setting the post variables derived from the data form equal to its own session variable. Then, when the user presses 'back' to get back to the data form, I have the data form check to see if these session variables are != "", and if so populate the data objects with their previous values.
However, this doesn't seem to work, and the session variables don't seem to be preserved if I press 'back'. Is this normal, and if so, is there a better way of getting this done?
Many thanks
Mark
-
magicrobotmonkey
- Forum Regular
- Posts: 888
- Joined: Sun Mar 21, 2004 1:09 pm
- Location: Cambridge, MA
Here's the code that doesn't seem to be working:
And once the variables have been posted to the next page (and I have checked that they are being successfully posted), I simply place
I have session_start() at the beginning of the code for each page.
I can't see anything wrong with this, but it doesn't seem to work - the text boxes (etc.) still remain empty on pressing 'back'.
Thanks
Mark
Code: Select all
<TD HEIGHT="20" WIDTH="604" STYLE="padding-right:16px" BGCOLOR="#000066"><FONT FACE="Tahoma" SIZE="2" COLOR="#FFFFFF">
<?php
if(isset($_SESSION['item_ID'])) echo '<INPUT TYPE="text" LENGTH="100" SIZE="26" NAME="txt_itemID" VALUE="'.$_SESSION['item_ID'].'">';
else echo '<INPUT TYPE="text" LENGTH="100" SIZE="26" NAME="txt_itemID">';
echo ' e.g. DE-10-157';
?>
</FONT></TD>Code: Select all
$_SESSION['item_ID'] = $_POST['txt_ItemID'];I can't see anything wrong with this, but it doesn't seem to work - the text boxes (etc.) still remain empty on pressing 'back'.
Thanks
Mark
-
magicrobotmonkey
- Forum Regular
- Posts: 888
- Joined: Sun Mar 21, 2004 1:09 pm
- Location: Cambridge, MA
-
magicrobotmonkey
- Forum Regular
- Posts: 888
- Joined: Sun Mar 21, 2004 1:09 pm
- Location: Cambridge, MA
Okay - I've check by echoing on the page following the data form that both $_POST contains content, and following setting, the $_SESSION variables contain content.
Yet, when I press 'back', echoing those same session variables, that I have confirmed contain the $_POST information, indicates that they are empty, i.e. they have lost that information.
Is this to do with the way browsers work, rather than the code? I don't understand.
Yet, when I press 'back', echoing those same session variables, that I have confirmed contain the $_POST information, indicates that they are empty, i.e. they have lost that information.
Is this to do with the way browsers work, rather than the code? I don't understand.
-
magicrobotmonkey
- Forum Regular
- Posts: 888
- Joined: Sun Mar 21, 2004 1:09 pm
- Location: Cambridge, MA
-
magicrobotmonkey
- Forum Regular
- Posts: 888
- Joined: Sun Mar 21, 2004 1:09 pm
- Location: Cambridge, MA
Personally I think it is bad practice to rely on the browsers back button as each browser tends to have a slightly different implementaion.
I think the problem is that when you hit the back button you are pulling the page from the browsers cache not a freshly generated page.
You could add headers to the page to prevent caching which should fix the problem, although some browsers ignore these headers.
You could also create your own back button on the page that follows the form which when used in conjunction with the above may help reloading the page.
I think the problem is that when you hit the back button you are pulling the page from the browsers cache not a freshly generated page.
You could add headers to the page to prevent caching which should fix the problem, although some browsers ignore these headers.
You could also create your own back button on the page that follows the form which when used in conjunction with the above may help reloading the page.
-
magicrobotmonkey
- Forum Regular
- Posts: 888
- Joined: Sun Mar 21, 2004 1:09 pm
- Location: Cambridge, MA