This is a discussion on losing form data within the PHP Language forums, part of the PHP Programming Forums category; i am validating form data, but when i redirect the user back to the form page to correct the errors, ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
digihoo wrote:
> i am validating form data, but when i redirect the user back to the > form page to correct the errors, all of the data they entered has > disappeared. The browser only displays what you send. If you want to send the same data a user submitted, you have to save it between the form processing script and the script that outputs that form. I'd do that with session variables: <?php // form processing script session_start(); if (isset($_POST['userdata']) { validate_data($_POST); // define according to your needs $_SESSION['userdata'] = $_POST['userdata']; } header('Location: form_output.php'); exit('Redirected <a href="form_output.php">here</a>.'); ?> and <?php // form output script session_start(); if (isset($_SESSION['userdata']) { $useradata = $_SESSION['userdata']; } else { $userdata = ''; // or some other default value } ?> <form method="post" action="form_process.php"> <input type="text" name="userdata" value="<?php echo $userdata; ?>" /> <input type="submit"> </form> Happy Coding :-) -- I have a spam filter working. To mail me include "urkxvq" (with or without the quotes) in the subject line, or your mail will be ruthlessly discarded. |
|
|||
|
i should have been more specific here. the form also loses its data if
the user just clicks the back button - without actually submitting the data. when they click forward to the form again, the data is also gone. i was told that this is caused by a bug in IE 6, and to put: header("Cache-control: private"); in the code before any HTML. however, this didn't solve the problem. is there a way to prevent form data from disappearing, whether or not it has been submitted into post variables? Thanks |