Keeping entered details when pressing BACK button

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
nutkenz
Forum Contributor
Posts: 155
Joined: Tue Jul 19, 2005 12:25 pm

Keeping entered details when pressing BACK button

Post by nutkenz »

When people registrate and get an error, they have to re-enter all information when they go back.

See http://ac-auction.com/register.php if you don't know what I'm talking about.

How can I make it so that all the info doesn't dissapear?
User avatar
wwwapu
Forum Contributor
Posts: 197
Joined: Wed Apr 07, 2004 11:57 am
Location: Turku, Finland

Post by wwwapu »

One way of doing it is by session

Code: Select all

<?php
session_start()

if(isset($_SESSION['form_field'])
	$form_field=$_SESSION['form_field'];
}else $form_sield='';
?>

<form ...>
<input type="text" name="form_field" value="<?php print $form_field ?>">
...
Set all fields to something and then store them into session and read from it.
mickd
Forum Contributor
Posts: 397
Joined: Tue Jun 21, 2005 9:05 am
Location: Australia

Post by mickd »

i think it depends on what vesion of IE and what IE you use that keeps the info when you press back.

i believe (not tested) is that you can use header() command to go back to the login page with the entered info in the url and using $_GET to display the info back in the form like

HANDLEREGISTER.PHP
(if headers were sent already for some reason you could use ob_Start
http://php.planetmirror.com/manual/en/f ... -start.php)

Code: Select all

$oldvalue = $_POST['oldvalue'];
$value = "value=" . $oldvalue . "";
header("location:register.php?$value");

REGISTER.PHP:

Code: Select all

<?php
$value = $_GET['value'];
echo '<input type="text" name="test" size="25" value="$value>"';
?>
like i said i got no idea if this works cos im pritty new to this stuff and its only a theory.


EDIT: or do what he said above ;) wow took me so long to post this lol.
dyonak
Forum Commoner
Posts: 56
Joined: Wed Jun 22, 2005 10:22 am
Location: Minneapolis, MN
Contact:

Post by dyonak »

Add the following line of code to your page(s), this assumes you already have a session_start(); call and should be added directly after it.

Code: Select all

header("Cache-control: private");
Some good information on sessions - http://www.phpfreaks.com/tutorials/41/0.php.
nutkenz
Forum Contributor
Posts: 155
Joined: Tue Jul 19, 2005 12:25 pm

Post by nutkenz »

dyonak wrote:Add the following line of code to your page(s), this assumes you already have a session_start(); call and should be added directly after it.

Code: Select all

header("Cache-control: private");
Some good information on sessions - http://www.phpfreaks.com/tutorials/41/0.php.
Thx, simple solutions r always best :)
Post Reply