losing form data

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, ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 10-01-2003
digihoo
 
Posts: n/a
Default losing form data

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.

Please Help.

Thanks
Reply With Quote
  #2 (permalink)  
Old 10-01-2003
Pedro
 
Posts: n/a
Default Re: losing form data

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.
Reply With Quote
  #3 (permalink)  
Old 10-02-2003
digihoo
 
Posts: n/a
Default Re: losing form data

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
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 05:58 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0