[web] How to keep input fields after page refresh?
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?
There's no automatic way of doing this. You have to do this manually by writing the correct value="..." in the HTML form.
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">
<input type="text" value="<?php $_POST['username']; ?>" name="username">
That would more likely be something like this:
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?
<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?
For perspective, you could also do it using javascript and a cookie (which, yes, depends on javascript and cookies).
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement