[web] How to keep input fields after page refresh?

Started by
4 comments, last by leiavoia 14 years, 1 month ago
I have a form with inputs, I want to keep the information after the page is refreshed or reloaded. For instance if the user inputs the captcha wrong I don't want them to have to fill out the form again. How is this normally done?
Advertisement
There's no automatic way of doing this. You have to do this manually by writing the correct value="..." in the HTML form.

<hr />
Sander Marechal<small>[Lone Wolves][Hearts for GNOME][E-mail][Forum FAQ]</small>

Quote:Original post by Sander
There's no automatic way of doing this. You have to do this manually by writing the correct value="..." in the HTML form.


Should I use $_SESSION to store the data or something else?
You could use something like this.

<input type="text" value="<?php $_POST['username']; ?>" name="username">
That would more likely be something like this:

<input type="text" value="<?php    if (isset($_POST['username'])) {        echo htmlspecialchars($_POST['username'], ENT_QUOTES);    }?>" name="username">

Make sure you escape any data before echoing it to the browser (as per the above example) – otherwise, what would happen if the user entered a " into the username box?

[Website] [+++ Divide By Cucumber Error. Please Reinstall Universe And Reboot +++]

For perspective, you could also do it using &#106avascript and a cookie (which, yes, depends on &#106avascript and cookies).

This topic is closed to new replies.

Advertisement