/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] Making SESSION override browser cache?

I’ve a form I wrote that, when page 1 is submitted to page 2 (which validates info and displays what the user input before it’s all inserted into the DB on a POST to page 3), all the POST values are turned into SESSION values.
That way, ideally, if the user goes back in their browser to page one to change something, the form fields will be populated with the SESSION values.

The browser cache is untrustworthy and, especially in IE, when they go back to page 1, the form is empty (which is what necessitated my creating SESSION values in the first place). And this works fine.

But here’s the problem:
I created an edit process, that when a previously submitted entry is selected, all the form fields populate with the DB saved values. And, from there the form process works as normal.
BUT! If during this edit they go from page 2 back to page 1, the form fields will always show the data it was originally populated with and NOT the SESSION values.

I know the SESSION values are working because, well, when the form is being filled it from blank, going back will populate the fields with the SESSION. And a print_r of SESSION on page 1 shows all the proper values.

(Just to illustrate, here’s a bit of script from page 1)

[code=php]
if (isset($_SESSION[‘txt_loc_code_1’])) {
$txt_loc_code_1_value = $_SESSION[‘txt_loc_code_1’];
}

[… snip …]

<input name=”txt_loc_code_1″ type=”text” id=”txt_loc_code_1″ value=”‘.$txt_loc_code_1_value.'” />

[/code]

Any ideas what I can do to make sure page 1 always displays the value I define in PHP rather than whatever the browser wants to put in there?
Thanks!

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@mikeroqApr 11.2011 — I would have to see the whole file to provide any meaningful help. Can you post it?
Copy linkTweet thisAlerts:
@NogDogApr 12.2011 — I think that is the nature of the "Back" button in most browsers: they never reload the page, they always use the cache. You could put a "Back" button into the HTML page itself that is actually a link or form submit button to that first page so that it gets reloaded from the server, and hope that users will use that instead of the browser button. You could also add some AJAX that would repopulate the form fields if the session data is found, triggered to execute as an onload event in the <body> tag.
Copy linkTweet thisAlerts:
@mechphistoauthorApr 12.2011 — You could put a "Back" button into the HTML page itself that is actually a link or form submit button to that first page so that it gets reloaded from the server [...][/QUOTE]

The link (Javascript) didn't make any difference, but I did try a submit button that directs back to the form page, and that works great! Perhaps inelegant, and I really should learn AJAX, but it works for me.

Thanks! ?
Copy linkTweet thisAlerts:
@NogDogApr 12.2011 — If it works, it's a good solution. ?
×

Success!

Help @mechphisto spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.2,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...