Cognito-forms – Keep Cognito form on every page

cognito-forms

I have a form that I want to display on every page. That's not a problem. But I want the entered information to be kept when you navigate to another page.

Is it possible?

Best Answer

While there is not an option in the Cognito Forms itself, you can add a bit of script inside your embed code to handle this:

<div class="cognito">
    <script src="https://services.cognitoforms.com/include/required"></script>
    <script src="https://services.cognitoforms.com/session/script/542df3c7-b22c-43b0-8491-3e0aeab0ce7c"></script>
    <script>
        var entry = localStorage["entry"];
        if (entry)
            entry = JSON.parse(entry);

        Cognito.load("forms", { id: "33", entry: entry });

        $(window).unload(function() { 
            localStorage["entry"] = JSON.stringify(Cognito.serialize(Cognito.Forms.model.entry));
        });
    </script>
</div>

Here is a link to a Pen showing this working: http://codepen.io/CognitoForms/pen/RNQVBL

You would need to start with the embed code for your form and then replace the final script block using the example above and replace the form number 33 with the number corresponding to your form. Also, this code assumes you have JQuery included on your page to make it easy to subscribe to the page unload event.

Finally, you will have to decide how to clear this form out, such as adding a bit of code to a page on your site that the page redirects to after it is submitted. Please give this a try and let me know how it goes!