Jump to content

text areas clearing when clicking back buton?


Round

Recommended Posts

Hello all,
I have a page that a user enters some text into text fields, then, via method="post" is sent to another page that inputs this text into the db and directs them to the next page, this works fine. However it also checks to see if they have left a text field empty, if they have, a message displays saying they have left a field empty and to go back and fill out all the text fields, again works ok but when they click back all of the text fields they have filled in have been cleared and means they would have to fill out the whole page again.

Is there a way of keeping all the text they have already typed when accessing the page via a back button?

Cheers
You can try different caching headers, but if you want to do it the right way, then not controlling what you should be controlling is a bad by design. The best thing to do, is to always return the form and fill in the inputs that contained valid data. This way you don't rely on something you have no control over (browser options), when that should never be the case because you can control the form process after a submit.


printf
All the variables transferred to your validationscript schould be retransfered to the form page.

[code]
-- FORM PAGE --
  <form action="validation.php" method="post">
    <input type="text" name="var1" value="<?php echo $_GET['var1'] ? $_GET['var1'] : ''; ?>">
    <input type="text" name="var2" value="<?php echo $_GET['var2'] ? $_GET['var2'] : ''; ?>">
    <input type="submit" value="Submit Form">
  </form>
----------------

-- VALIDATION PAGE --
<?php
$error = null;
if(!preg_match('/...regex.../', $_POST['var1'])) {
  $error .= "<br><font color="red">Var1 not valid</font>";
}
if(!preg_match('/...regex.../', $_POST['var2'])) {
  $error .= "<br><font color="red">Var2 not valid</font>";
}

if($error) {
  $error .= "<a href='form.php?var1=" . $_POST['var1'] . "&var2=" . $_POST['var2'] . "' target='_self'>Pleas adjust your data.</a>'"
  exit(echo $error);
}
  ....
?>
-----------------------
[/code]

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.