0

I have a long html form and I want to prevent that a user accidentally loses all inputs.

In Chrome, I can close the tab and restore it without losing any input. However, if I reload the page (F5) all input fields are cleared.
In Firefox, I can reload the page (F5) without losing any input. However if close the tab and restore it all input fields are cleared.

I was thinking of an Ajax or localStorage solution, so I can constantly save the current input and restore it if needed, but I was hoping for some HTML5 setting (without javascript), to tell the browser that I want to keep the input after reloading.

While the opposite (delete everything on refresh) seems easy (autocomplete="off") I had no luck using autocomplete="on"

Note: this is all before clicking the submit button. After the user clicked on the submit button it does not matter whether the inputs are still there or not.

EDIT: all the other questions propose using javascript/localStorage. I can solve the problem using javascript but I am asking if there is an easier way, like a HTML5 setting to let the browser handle it.

SackZement
  • 33
  • 7
  • You can detect if the user is leaving the page and save the form data to cookies if so. https://stackoverflow.com/questions/7080269/javascript-before-leaving-the-page https://stackoverflow.com/questions/1458724/how-do-i-set-unset-a-cookie-with-jquery – Combine Sep 04 '18 at 06:34
  • [check this](https://stackoverflow.com/questions/17591447/how-to-reload-current-page-without-losing-any-form-data) – Margon Sep 04 '18 at 06:36
  • The answer is no. There is no HTML5 setting to keep the form intact. You can use server session storage too – mplungjan Sep 04 '18 at 07:22
  • @mplungjan can you post it as an answer so I can accept it? – SackZement Sep 04 '18 at 07:24
  • It's ok. I have added one more for you: https://stackoverflow.com/questions/14420624/how-to-keep-changed-form-content-when-leaving-and-going-back-to-https-page-wor – mplungjan Sep 04 '18 at 07:29

0 Answers0