I have a simple form, and I'm trying to save the form data throughout its edit /submission. All seems to work fine except for dropdown boxes. Is there something different I should be doing? 🙁
EG:
form.php:
<?
// [ START SESSION ]
session_start();
header("Cache-control: private"); // IE 6 Fix.
?>
<html>
<head>
<title>form.php</title>
</head>
<body>
<form method="post" action="preview.php">
First Name:<input type="text" name="First_Name" value="<? print("$_SESSION[First_Name]");?>" /><br />
Last Name:<input type="text" name="Last_Name" value="<? print("$_SESSION[Last_Name]");?>" /><br />
<select name="dropdown" value="<?print("$_POST[dropdown]");?>" >
<option ></option>
<option value="Cats">Cats</option>
<option value="Dogs">Dogs</option>
<option value="Elephants">Elephants</option>
</select>
<br /><br />
<input type="submit" value="submit">
</form>
</body>
</html>
preview.php:
<?
// [ START SESSION ]
session_start();
header("Cache-control: private"); // IE 6 Fix.
// actions to take from buttons
if (isset($_POST["goBack"])) { // Go Back and Edit
header("Location: form.php");
} else {
if (isset($_POST["Send"])) { // Continue & Process the form
header("Location: process.php");
}
}
// Dynamically Assign Key & Value to each Post
foreach($_POST as $key=>$value){
$_SESSION[$key]=$value;
}
?>
<html>
<head>
<title>preview.php</title>
</head>
<body>
<b>Form Results:</b><br />
<?
// Echo Results
print("First Name is: $First_Name<br />");
print("Last Name is: $Last_Name<br />");
print("You selected: $dropdown<br /><br />");
?>
<form method="post" action="preview.php">
<input type="submit" name="goBack" value="Edit"><input type="submit" name="Send" value="OK">
</form>
</body>
</html>
If the browser 'back' button is used, the dropdown data is returned. However, if the 'edit'(submit) button is used, the data is NOT returned.
Thanks for looking!