If you want to keep the values of the form fields, you have to save it somewhere. A good place to do that are cookies. But that could be a security lack if the form contains secret data like the customers bank information. In this case, store the data in a session (which is located on the webserver). You have to do this everytime the customer sends new values. This is pedantic but the only way I know (and afaik the only way to do this).
To store the values everytime, independently of the button the customer used, all of the three buttons must be submit-buttons.
This is a sample page. If every page is designed like this one, it should work.
<?php
// make the session accessible
session_start();
// is there already a submittion of form data?
if (!empty($_POST['submit']))
{
// save everything but the value of "submit" and "backurl" submitted by post into the session
foreach (array_keys($_POST) as $cKey)
{
if ($cKey != "submit" && $cKey != "backurl")
$_SESSION[$cKey] = $_POST[$cKey];
}
// back, refresh or forward?
switch ($_POST['submit'])
{
case "BACK":
// redirect the customer back
header("Location: ".$_POST['backurl']);
// alternativly, you could use javascript if the way above causes trouble:
// echo "<script>history.go(-2);</script>";
// prevent every further output
exit;
case "FORWARD":
// redirect the customer to the next page. you have to modify this lines on every page to make the script work!
header("Location: URLOFTHENEXTPAGE");
// or
// echo "<script>document.location.href='URLOFTHENEXTPAGE';</script>";
exit;
case "REFRESH":
// the customer would like to see this page again, nothing to do...
break;
}
?>
<html>
<head>
<title>Keep-The-Values-Form Sample Page</title>
</head>
<body>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<input type="text" size="50" maxlength="255" name="mytextfield" value="<?php echo $_SESSION['mytextfield']; ?>">
<!-- this hidden form field determines where to go backward -->
<input type="hidden" name="backurl" value="<?php echo $_SERVER['HTTP_REFERER']; ?>">
<input type="submit" name="submit" value="BACK">
<input type="submit" name="submit" value="REFRESH">
<input type="submit" name="submit" value="FORWARD">
</form>
</body>
</html>
I wrote the source code in the forum editor, without tabstops, syntax highlighting etc. It is not tested and I'm not 100% sure that it will work. If there are parse errors or something else, post it here.
Good luck 😉
(Without this paragraph, this message is 2426 characters long!)