I have this simple form.
a.php
<html>
<head>
</head>
<body>
<?
echo "
<form action = 'a2.php' method = 'post'>
<input type = 'text' name = 'name'>
<input type = 'submit' value = 'SEND' name = 'send'>
</form>
";
?>
</body>
</html>
a2.php
<?
$name = $_REQUEST ['name'];
echo $name;
echo "
<form action = 'a2.php' method = 'post'>
<input type = 'submit' value = 'EDIT' name = 'edit'>
</form>
";
?>
How can I keep the value introduced when I click EDIT and i’m back to the first form?
Thanks.
EDIT 2: using hidden inputs
on a2.php just put another
<input type="hidden" name="hidden_name" value="{$_POST['name']}" />after you hit submit on a2.php (BTW for it to go back to a.php, you need to change the formaction="a.php"on a2.php), a.php will have a$_POST['hidden_name'], that will contain the value from the first iteration.EDIT: before you start handling
$_SESSIONvariables, first initiate the session before any html output with asession_start()function.Use a superglobal like
$_SESSIONso in your case you would need to fetch the incoming in a2.php$_SESSION['name'] = $_POST['name']and refer to the$_SESSION['name']in youra.php. Remember that$_SESSION['name']will retain the last assigned value until the the session is terminated, I.e. browser window is closed.You can read more in http://www.php.net/manual/en/reserved.variables.session.php
Also about
session_start: http://www.php.net/manual/en/function.session-start.php