Jump to content
  • Advertisement
Sign in to follow this  
RetroBilly

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

This topic is 2994 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Advertisement
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!