Save information if user leaves page

Asked

Viewed 51 times

1

The page in question has a form right away, this form has only three fields, which are the basic information required, after clicking the button, the fields will disappear and new fields will appear with complementary information.

The problem is, the client doesn’t want two emails sent, what he wants is: - If the customer fills in the rest of the form, the email goes with all the information. - If the customer fills in the first form and leaves the page when the second one is opened, only the information of the first one is sent.

I understand that using BD the solution is simple, but I am looking for a solution that runs only on the customer.

2 answers

0

You can use localStorage, to store some objetos/variáveis in the customer’s browser, this localStorage does not expire when the browser closes.

localStorage documentation

Examples to record:

localStorage.setItem("Nome", "Otavio Rocha");
localStorage.setItem("formPreenchido", meuObjetoFormulario);
localStorage.setItem("umaVariavelQualquer", minhaVariavelQualquer);

To recover:

var nome = localStorage.getItem("Nome"); 
var obj = localStorage.getItem("formPreenchido"); 
var var1 = localStorage.getItem("umaVariavelQualquer"); 

0

Browser other questions tagged

You are not signed in. Login or sign up in order to post.