On Nov 26, 2004, at 7:59 PM, Cyrus wrote:

Dear All,

I have a problem of back to the previous page in php.....
I need to create a form let people to fill in .It can let user to preview the form, if information is not correct , user can back to previous page and correct it,
I have used the javascript : OnClick='history.go(-1)' and OnClick='history.back()' in php , but it can not works....pls help me.


Thanks and Regards,

Cyrus Chan

What I do is store all the fields in $_SESSION variables, so when you go back to the page, if they filled that particular field out, it should show what they have already completed.


------------------
<?php
session_start();

if ($_POST["submitted"] == 1) {
        $_SESSION["field1"] = $_POST["something"];
        $_SESSION["field2"] = $_POST["pizza"];
}
?>


<form action="wherever.php" method="post">
<input type="text" name="something" value="<? echo $_SESSION["field1"]; ?>"/>
<input type="text" name="pizza" value="<? echo $_SESSION["field2"]; ?>"/>
<input type="submit" value="GO"/>
<input type="hidden" name="submitted" value="1"/>
</form>
------------------


So, there's no need to use javascript or to actually "go back." You can just "redirect" to that page and have it "remember" the variables. To redirect back to it, use header("location: http://mysite.com/wherever.php";); It is not *always* necessary to use the absolute path to indicate that particular page in the header() function, but it doesn't hurt.

Sorry if I have rambled on or confused you - it's late and I'm sleepy. Good luck with that.

~Philip

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Reply via email to