Save information if user exits the page

3

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

The problem is that the client does not want two emails to be sent, what he wants is that:  - If the customer completes the rest of the form, the email goes with all the information.  - If the client completes the first form and exits the page when the second is opened, only the first information is sent.

I understand that using BD is a simple solution, but I'm looking for a solution that only runs on the client.

    
asked by anonymous 02.08.2018 / 22:20

2 answers

2

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

Storage documentation

Examples to write:

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"); 
    
03.08.2018 / 12:46
0

Use the example below:

<body onunload="Funcao();">

More details on this site: link

    
02.08.2018 / 22:25