losing form data

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • digihoo

    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
  • Pedro

    #2
    Re: losing form data

    digihoo wrote:[color=blue]
    > 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.[/color]

    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('Locatio n: form_output.php ');
    exit('Redirecte d <a href="form_outp ut.php">here</a>.');
    ?>

    and

    <?php // form output script
    session_start() ;
    if (isset($_SESSIO N['userdata']) {
    $useradata = $_SESSION['userdata'];
    } else {
    $userdata = ''; // or some other default value
    }
    ?>
    <form method="post" action="form_pr ocess.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.

    Comment

    • digihoo

      #3
      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

      Comment

      Working...