Populate hidden fields from localStorage
-
Hi, i have a form on page1 when submitted i store the value in local storage and redirect to page2, in the page 2 i have a forminator form with hidden fields i want to populate, i followed one of your gists for populating hidden fields from url but still cant populate the hidden fields, i created a shortcode that display the data from localStorage then populate the fields, the display works fine but the fields are not populated, here my code can you help with this matter please ?
<script> jQuery(document).ready(function($) { // Retrieve stored data from local storage var storedData = JSON.parse(localStorage.getItem(‘siretData’)); var populateLocalStorageField = <?php echo (isset($_GET[‘auto_populate_local_storage_field’]) && $_GET[‘auto_populate_local_storage_field’] === ‘true’) ? ‘true’ : ‘false’; ?>; if (storedData) { // Populate Forminator form fields with stored data $(‘[name=”hidden-1″]’).val(storedData.field1); $(‘[name=”hidden-2″]’).val(storedData.field2); $(‘[name=”hidden-3″]’).val(storedData.field3); $(‘[name=”hidden-4″]’).val(storedData.field4); $(‘[name=”hidden-5″]’).val(storedData.field5); $(‘[name=”hidden-6″]’).val(storedData.field6); $(‘[name=”hidden-7″]’).val(storedData.field7); $(‘[name=”hidden-8″]’).val(storedData.field8); $(‘[name=”hidden-9″]’).val(storedData.field9); $(‘[name=”hidden-10″]’).val(storedData.field10); // Display the populated field values $(‘#populated-data’).html( ‘<p>SIRET: ‘ + storedData.field1 + ‘</p>’ + ‘<p>Société: ‘ + storedData.field2 + ‘</p>’ + ‘<p>Ville: ‘ + storedData.field3 + ‘</p>’ + ‘<p>Adresse: ‘ + storedData.field4 + ‘</p>’ + ‘<p>Code Postal: ‘ + storedData.field5 + ‘</p>’ + ‘<p>Prénom: ‘ + storedData.field6 + ‘</p>’ + ‘<p>Nom: ‘ + storedData.field7 + ‘</p>’ + ‘<p>Email: ‘ + storedData.field8 + ‘</p>’ + ‘<p>Tel: ‘ + storedData.field9 + ‘</p>’ + ‘<p>Pays: ‘ + storedData.field10 + ‘</p>’ ); } // Clear stored data from local storage after use localStorage.removeItem(‘siretData’); }); </script>
The page I need help with: [log in to see the link]
- The topic ‘Populate hidden fields from localStorage’ is closed to new replies.