tzortzik
tzortzik

Reputation: 5143

Best way to not lose data filled in a browser form

I have an HTML form. I am filling it partially with data. I want to do a few things to protect the data that was filled and I don't know what is the best solution.

  1. If the user accidentally presses the close button of it's browser, the filled data is lost
  2. If the user accidentally presses on a link inside the webpage, he will lose the filled data
  3. If the user clicks on the refresh button, he may lose that data (Chrome and Firefox shows an alert to inform you that you are about to lose data if you refresh the webpage)

What is the best way to protect the data from the form?

I was thinking that if the user makes one of those three actions, a window should appear and inform him about the action that will take place.

Upvotes: 0

Views: 978

Answers (1)

Bergi
Bergi

Reputation: 665486

What is the best way to protect the data from the form?

A more userfriendly way than showing warning messages would be just to autosave the data and not letting it get lost. On every input action, store the form values in the localStorage. When the form is loaded empty, restore them. When the form is submitted [successfully], clear them.

Upvotes: 2

Related Questions