Jump to content

Form remembering values?


EchoFool

Recommended Posts

Why are sessions problematic?

 

When you send the form, on the receiving page just create temp variables like this:

 

 

if ($error_exists or some other condition) {

    $_SESSION['username'] - $_POST['username'];

    $_SESSION['phone'] - $_POST['phone'];

    header("Location: form.html");

    exit;

}

 

and then on the form itself echo out the values if they are not empty like this:

 

<form>

    <input type="text" name="username" value="<?php echo $_SESSION['username']; ?>" />

    <input type="text" name="phone" value="<?php echo $_SESSION['phone']; ?>" />

</form>

 

and then maybe kill the session values so they don't get re-used

 

$_SESSION['username'] = null;

$_SESSION['phone] = null;

 

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.