CMS Development

CristianSabogal
Member

How I can store values of form fields in sessionStorage or similary before the submit?

SOLVE

I've a session area protected by login/registration. In this area I did set a form that collecting certain information to create records in a custom object. This works fine.

 

Now, my users ask me Why my progress in form don't stay in each field (even before of submit form) if I'm logged in? I've active to this form the option "Pre-populated fields" but seems that don´t works.

 

Actually for example, if i and any user fill only some fields and something happen (close browser, logout) the form is reset it. losing all preview data filled.

 

There is a way to save or pre-save this data either browser or session?

0 Upvotes
1 Accepted solution
piersg
Solution
Key Advisor

How I can store values of form fields in sessionStorage or similary before the submit?

SOLVE

You could do this with local storage (better than session storage):

window.addEventListener('message', event => {
    if(event.data.type === 'hsFormCallback' && event.data.eventName === 'onFormSubmit') {
    	let email = document.querySelector('input[type=email]').value;
    	localStorage.setItem('email', email);
        // repeat for other values you want
    }
});

View solution in original post

1 Reply 1
piersg
Solution
Key Advisor

How I can store values of form fields in sessionStorage or similary before the submit?

SOLVE

You could do this with local storage (better than session storage):

window.addEventListener('message', event => {
    if(event.data.type === 'hsFormCallback' && event.data.eventName === 'onFormSubmit') {
    	let email = document.querySelector('input[type=email]').value;
    	localStorage.setItem('email', email);
        // repeat for other values you want
    }
});