Sign in to follow this  
SteveDeFacto

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

Recommended Posts

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?

Share this post


Link to post
Share on other sites
There's no automatic way of doing this. You have to do this manually by writing the correct value="..." in the HTML form.

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
For perspective, you could also do it using javascript and a cookie (which, yes, depends on javascript and cookies).

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this