Suppose we have a form, and its validations written with PHP. The variables are collected with POST, there are two fields (username and password), and a submit button.
Well, the user enters his credentials and by some chance he mistypes the password. I'd like the username to at least be etched into <input>
it so I don't have to type it in again.
If you want the form to display the same user when the username/password check is wrong you can use the following code:
As you can see, in case the form had been previously submitted, the field
value
will be filled with the value of the form usinghtmlspecialchars()
to convert special characters into HTML entities (such as quotes"
that would close the fieldvalue
prematurely).You can save it in the browser cache with javascript. In the part where the data is received by:
And when you return to the form through the DOM you can put the value to the text box with:
Bibliography of interest: