Jump to content

Problem When Browser's "Back" Button is Pressed


creacon

Recommended Posts

When the first page is filled out, all the data are stored in an array which is then stored as a session variable so as to be available to the next two pages. When the second page is displayed and the oprator clicks on the browser's "Back" button, the first page is displayed with no data.I need for the form to retain/refresh the data in the form when the operator clicks on the browser's back button, but:1. I can't find/figure out how to detect the event, and2. Even though, in each form field, I have the following

value="<?php echo $arrappl['...']; ?>"

where $arrappl is the array containing the entered field values, and '...' is the field name (array element).I've even re-initialized $arrappl from the system variable, just to be sureI've tried everything I can think of with my very limited knowledge, but no luck. I'd be very grateful if someone would tell me how to accomplish this.

Link to comment
Share on other sites

try javascript and save to cookie, "id number of topic + the message"
I don't think I understand this. What I need to do should be, I think, in php code, namely: if the page is loaded from the previous page, then clear the array and session varable, but if it's loaded as a result of the back button (i.e. from the SUCCEEDING page), then simply re-initialize the array from the session variable.My problem is that I can't find out how to detect the browser's back button, or which page loaded the form.
Link to comment
Share on other sites

you mean :) REQUEST_URI
I think he really meant HTTP_REFERER (gets referring page)http://php.net/manual/en/reserved.variables.server.phpREQUEST_URI (gets current page)http://php.about.com/od/learnphp/qt/_SERVER_PHP.htmdo a test in the form pages to detect what the referring page is. if its coming from a step ahead, then it could be because of a back button, so load the session variables. If its any other page (a step before) then load the form without session variables.
Link to comment
Share on other sites

I think he really meant HTTP_REFERER (gets referring page)http://php.net/manual/en/reserved.variables.server.phpREQUEST_URI (gets current page)http://php.about.com/od/learnphp/qt/_SERVER_PHP.htmdo a test in the form pages to detect what the referring page is. if its coming from a step ahead, then it could be because of a back button, so load the session variables. If its any other page (a step before) then load the form without session variables.
This only halfway worked. Here's what I did for testing purposes:
$referrer = $_SERVER['HTTP_REFERER'];// "WOTCSignin.php" is the PRECEDING pageif (strpos($referrer,"WOTCSignin.php") > 0)   {echo "Referred from Signin Page";   // the above displays when this page is referred by the WOTCSignin.php pageelse   // This should restore the array from the   // Session  variable when the referring page   // IS NOT the preceding page (i.e. Back pressed from suceeding page"   {$arrappl = $_SESSION['sesarrappl'];}

The first part works OK (i.e. when the sign in page redirects to this page) but when the BACK button is pressed the suceeding page is apparently not detected (i.e. "WOTCPg2.php"), and the page simply displays as it did when the Sign In page redirected to it (i.e. with the echo display still showing). I don't know if that's just residue because the form isn't being refreshed, or if the WOTCPg2.php is not being recognized as a referrer when the Back button is pressed.Am I missing something???

Link to comment
Share on other sites

I think he really meant HTTP_REFERER (gets referring page)http://php.net/manual/en/reserved.variables.server.phpREQUEST_URI (gets current page)http://php.about.com/od/learnphp/qt/_SERVER_PHP.htmdo a test in the form pages to detect what the referring page is. if its coming from a step ahead, then it could be because of a back button, so load the session variables. If its any other page (a step before) then load the form without session variables.
sorry
Link to comment
Share on other sites

sorry
S'aright. I just don't understand what's happening. I even added a "$referrer = "";" statement immediately before redirecting to the second page, just make sure there'd be no confusion, but the same thing happens. It's as though when the back button is pressed from page 2 and page 1 is redisplayed, all the php code at the very beginning of page 1 is ignored. It's only when the signin page redirects to page 1, that the code is executed.
Link to comment
Share on other sites

now i understand the situation :) finally :)try posting to ajax.or maybe send the message to GET<form action="something" method="get"><---
I haven't learned yet just what ajax is, so I don't know what posting to ajax means. My form's action, however, is, action="WOTCPg1.php" (which is this page) in order that all the tons of php code in the "if (isset($_POST['submit'])) ..." group will execute when the Submit button is pressed. That's what stores all the entered information, and creates the session variables for the data to be passed to the next two pages.Is there some other event that could be coded tol do what you're suggesting?
Link to comment
Share on other sites

I haven't learned yet just what ajax is, so I don't know what posting to ajax means. My form's action, however, is, action="WOTCPg1.php" (which is this page) in order that all the tons of php code in the "if (isset($_POST['submit'])) ..." group will execute when the Submit button is pressed. That's what stores all the entered information, and creates the session variables for the data to be passed to the next two pages.Is there some other event that could be coded tol do what you're suggesting?
you can just modifiyng the if state to thisif (isset($_GET['submit'])){}and dont forget, the search of every forum it's a get send
Link to comment
Share on other sites

S'aright. I just don't understand what's happening. I even added a "$referrer = "";" statement immediately before redirecting to the second page, just make sure there'd be no confusion, but the same thing happens. It's as though when the back button is pressed from page 2 and page 1 is redisplayed, all the php code at the very beginning of page 1 is ignored. It's only when the signin page redirects to page 1, that the code is executed.
can you show us the code your using for these two pages?I think you should be using SESSION variables to be storing all this. that way you can track whether the page has been accessed no matter which page they're on.
Link to comment
Share on other sites

can you show us the code your using for these two pages?I think you should be using SESSION variables to be storing all this. that way you can track whether the page has been accessed no matter which page they're on.
Actually I have been using session variables. When the SUBMIT button is pressed on page 1, all of the fields are loaded into an array, and the array then stored as a session variable. I had previously included a line of code to re-initialize the array variable from the session variable, but I guess I had it in the wrong place, because it didn't work.I removed all the "referrer" code, and placed the line:
	//	Re-initialize the Page 1 Info Array	//	For new applications it w/be null	$arrappl = $_SESSION['sesarrappl'];	

at the top of the page, immediately after the "session_start();" statment, and VOILA! now it works great.Then for good housekeeping, I cleared the session variable at the biginning of the "Signin" page (which preceeds page 1), and after all the submit logic on page 3, just before the redirection (i.e. there're two buttons on page 3; one exits the system, and the other cycles back to page 1 to allow another application).Thanks everyone for your kind help. I truly appreciate it (I love this forum).

Link to comment
Share on other sites

Hi!Try This Code:xxxxxxxxxxxxxxxxxxxxindex.php<?phpsession_start();if (!isset($_SESSION["Return"])){ $name = ""; $email = "";}else{ $name = $_SESSION["Name"]; $email = $_SESSION["Email"];}?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"><html><head></head><body><form method="post" action="form.php" name="form1">Name:</label> <input type="text" name="name" id="name" value="<?php print $name; ?>"><br>Email:</label> <input type="text" name="email" id="email" value="<?php print $email; ?>"><br><input id="subbut" type="submit" value="Submit"></form></body></html>xxxxxxxxxxxxxxxxxxxxform.php<?php$name = $_REQUEST['name'];$email = $_REQUEST['email'];if ($name == ""){ $setError = "Please Enter Your Name";}else if ($email == ""){ $setError = "Please Enter Your Email";}else if ($name == "" && $email == ""){ $setError = "Please Enter Your Name & Email";}else{ session_start(); $_SESSION["Return"] = 1; $_SESSION["Name"] = $_REQUEST['name']; $_SESSION["Email"] = $_REQUEST['email']; print "All Your Session Has Been Created Successfully, Now U Can Go Back";}xxxxxxxxxxxxxxxxxxxxThnx & Regards: Hungry Mind (http://hungrymind.tk/)

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...