• Resolved omarsekkkk

    (@omarsekkkk)


    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]

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Support Patrick – WPMU DEV Support

    (@wpmudevsupport12)

    Hi @omarsekkkk

    I hope you are doing well.

    Seems your code got corrupted due forum, could you upload it to https://gist.github.com/ or https://pastebin.com/?

    Wouldn’t you mind please also sharing an example of a string that is saved in local storage?

    We do have a code to store and recover the data but it uses Cookie, is it the code that you are testing? https://gist.github.com/wpmudev-sls/9917696b87543e3edb92e84f41933be0

    Another option would be using query strings https://wpmudev.com/docs/wpmu-dev-plugins/forminator/#pre-populate-form-field-values

    Best Regards
    Patrick Freitas

    Thread Starter omarsekkkk

    (@omarsekkkk)

    sure, actually the code is working i can display the values from local storage to the page, the values are populated in the fields, when i inspect the hidden fields, i see that my data is there, but when i submit the form i dont see that data in submissions, here s the code i use :

    https://pastebin.com/9jfxnFUy

    thanks,

    Plugin Support Williams – WPMU DEV Support

    (@wpmudev-support8)

    Hi @omarsekkkk

    I hope you’re well today!

    Since 1.24 release hidden fields are additionally validated and sanitized so code like this will not work. Basically, if you assign any value to hidden field other than the one assigned by the plugin itself (so depending on the hidden field configuration) – this value would be visible in HTML markup but it will not be saved and instead it will be reverted to whatever is configured in hidden field configuration in form builder.

    The simplest and fastest workaround in this case will be to simply replace “hidden” type fields on the form with “input” type fields and update the code accordingly, for example:

    this line

    $('input[name="hidden-1"]').val(storedData.field1);

    could be changed to

    $('input[name="text-1"]').val(storedData.field1);

    I believe you get the idea. You can then also hide those fields with CSS (note: with custom CSS and NOT with the fields’ “visibility” settings!) so they would be not visible in the form.

    They would then behave similar to hidden fields but would carry over and save the data you set with your custom JS code.

    Best regards,
    Adam

    Thread Starter omarsekkkk

    (@omarsekkkk)

    thats exatly what i did thank you so much for your response, i understood this and replaced the hidden fields with input fields, i have another but same problem i think we can look into in the same thread, please aknowledge if i need to create a new question for this matter, its on this page : https://kessef-business.com/demande-ouverture-compte/step-3/

    i have a seach form and i search for the entries by ID, (please test with id = 31) i would like to populate a forminator form fields in the same page with the data i get from the API, i get the data, encode it JSON, and parse the json to display the results, can you help with this code i writed, i cant get the fields to populate when the search form is submitted and the ID exists

    https://pastebin.com/siJp3SGJ

    Thanks

    Plugin Support Williams – WPMU DEV Support

    (@wpmudev-support8)

    Hi @omarsekkkk

    Thanks for response!

    I took a look into it but this is way more complex and not quite the same as the initial issue here.

    It would actually be better to start a separate topic about this.

    In that new topic, it would be great if you could also:

    1. attach export of the form itself (and, again, the link to your code)

    To share form export:
    – go to the “Forminator -> Forms” page and click on a “gear” icon next to the form in question
    – select “export” option
    – copy given code and put it at https://pastebin.com
    – include link to that “paste” in your post

    2. also suggest some example submission IDs that we could use in the form on your site to test it there (I tried some random ones but didn’t “hit” – I got only “no data”)

    Best regards,
    Adam

    Thread Starter omarsekkkk

    (@omarsekkkk)

    Plugin Support Jair – WPMU DEV Support

    (@wpmudevsupport15)

    Hi @omarsekkkk,

    We are marking this topic as resolved accordingly as the new one created.

    Kind regards,
    Zafer

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Populate hidden fields from localStorage’ is closed to new replies.