Forminator Hidden Field Populated By Local Storage Value
-
Hello, Forminator was recently showed to me, and it’s so great. I started changing all my sites over to it.
I just ran into a slightly more complex use case, where I want to include a value from localStorage in my form submission. To do this, I figured I would use a custom hidden field. Once the page loads, I use a javascript snippet to look for the field by name and update the value, then a few seconds later, I read the value to make sure it worked.<script> setTimeout(() => { console.log('looking for the value'); var hiddenElement = document.getElementsByName('hidden-1'); if (hiddenElement) { var val = localStorage.getItem('utm_source') console.log('updating element to: ', val); hiddenElement.value = val; } else { console.error('Element not found!'); } }, 2000); setTimeout(() => { console.log('looking for the value'); var hiddenElement = document.getElementsByName('hidden-1'); console.log('after 5', hiddenElement.value) }, 5000); </script>
It does seem to change the value client side, but the email and submission have the original value of the custom field.
Has anyone tried something like this successfully, or see where I might be missing something?
- The topic ‘Forminator Hidden Field Populated By Local Storage Value’ is closed to new replies.