search

Home  >  Q&A  >  body text

javascript - How to restore html form

Suppose I have a form

<form>
<input name="username"/>
</form>

Now when the user enters the username, the second time the user comes to the page again, the username has been obtained from the server. How can the input on the page display the username that the user has entered

扔个三星炸死你扔个三星炸死你2707 days ago705

reply all(3)I'll reply

  • 淡淡烟草味

    淡淡烟草味2017-06-30 09:57:18

    Two solutions
    Backend: Get the data from the backend and assign it to the input
    Frontend: Save the input value to local cookie or localStorage

    reply
    0
  • 滿天的星座

    滿天的星座2017-06-30 09:57:18

    The first one

    Server

    $_SESSION['username'] = $_POST['username'];

    Template

    <input name="username" value ="<?=$_SESSION['username']?>"/>

    Second type

    Refer to the comment function of this blog website. After the user enters the user name and email address for the first time comment, localstorage caches it. Next time, the cache is directly read and assigned to the value of the form

    https://blog.codefun.cn/blog/...

    reply
    0
  • 習慣沉默

    習慣沉默2017-06-30 09:57:18

    Aren’t your inputs stored in the background data? Page loading request data.

    reply
    0
  • Cancelreply