Best Way For Back Button To Leave Form Data

后端 未结 3 1788
迷失自我
迷失自我 2021-01-06 08:16

I\'m creating a web page based on user input from a form. After the user sees the generated page I want to allow them to press the back button and make changes to the form.

3条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-06 09:01

    After the user sees the generated page I want to allow them to press the back button and make changes to the form. I would like to display the form as they had filled it out previously.

    There is no need to add any clever fancy code; that is what browsers will do by default, unless you take active steps to prevent it, such as:

    • breaking the cache with Cache-Control/Pragma headers
    • generating the form page itself from the response to a POST (use POST-Redirect-GET instead)
    • generating the form elements from script

    Cookie solutions are fragile and need special handling if you don't want two tabs open at once to get very confused. Make it easy for yourself: let the browser do the work.

提交回复
热议问题