Re: Cookie hidden fields don't work if custom html is used for known visitors

SanfordWhiteman
Level 10 - Community Moderator

Re: Cookie hidden fields don't work if custom html is used for known visitors

You just need the teknklFormsPlus-0.2.0-Util include <script> and the code from the JS pane in another <script>. The other stuff is just there to have the demo load an actual form.

Boone_White1
Level 2

Re: Cookie hidden fields don't work if custom html is used for known visitors

Awesome, that makes total sense!

Does this looked like it was installed correctly? I wasn't getting UTM results pulled-in. I figure i have it installed wrong.

Screen Shot 2018-03-30 at 3.27.57 PM.png

SanfordWhiteman
Level 10 - Community Moderator

Re: Cookie hidden fields don't work if custom html is used for known visitors

Can you provide your URL please?

Boone_White1
Level 2

Re: Cookie hidden fields don't work if custom html is used for known visitors

SanfordWhiteman
Level 10 - Community Moderator

Re: Cookie hidden fields don't work if custom html is used for known visitors

If you look in your browser's F12 Console you'll see this 412 error on formsplus-util:

pastedImage_1.png

That's 'cuz you have to download the JS file onto your own server and serve it from there. It's for your own protection -- I can't afford to run a CDN for everyone who might use the file!

Boone_White1
Level 2

Re: Cookie hidden fields don't work if custom html is used for known visitors

My bad lol. That makes sense the script works great!

Thank you so much!

Boone White

Shonal_Narayan2
Level 1

Re: Cookie hidden fields don't work if custom html is used for known visitors

Hi Sanford,

We are having an issue related the topic, and wondering if you can help this. I've added the code you provided above and updated with our form in the link:

However, I checked the record and the person source and promo code fields didn't update.

Here is the parameters I tested:

https://pages.messagesystems.com/Hidden_field_Test_Page.html?src=Blog&pc=test-sso-utms%20&utm_source...

Here is the script I added:

<script>

      MktoForms2.whenReady(function(form) {

  

   var hiddenFieldMap = {

      LeadSource: {

         channel: "query",

         selector: "utm_leadsource"

      },

       Promo_Code__c: {

         channel: "query",

         selector: "utm_promo_code"

      },

       RF_Confidence_Level__c: {

         channel: "query",

         selector: "utm_rf_confidence_level"

      },

       RF_HQ_Company_Name__c: {

         channel: "query",

         selector: "utm_rf_hq_company_name"

      },

       RF_HQ_Industry__c: {

         channel: "query",

         selector: "utm_rf_hq_industry"

      },

       RF_GHQ_Annual_Revenue__c: {

         channel: "query",

         selector: "utm_rf_ghq_annual_revenue"

      },

       RF_SITE_Phone__c: {

         channel: "query",

         selector: "utm_rf_site_phone"

      },

       RF_SITE_City__c: {

         channel: "query",

         selector: "utm_rf_site_city"

      },

       RF_SITE_State__c: {

         channel: "query",

         selector: "utm_rf_site_state"

      },

       RF_SITE_Zip__c: {

         channel: "query",

         selector: "utm_rf_site_zip"

      },

       RF_SITE_Country__c: {

         channel: "query",

         selector: "utm_rf_site_country"

      },

       RF_HQ_Website__c: {

         channel: "query",

         selector: "utm_rf_hq_website"

      },

       RF_HQ_Phone__c: {

         channel: "query",

         selector: "utm_rf_hq_phone"

      },

       RF_Trade_Name__c: {

         channel: "query",

         selector: "utm_rf_trade_name"

      },

       RF_Company_Name__c: {

         channel: "query",

         selector: "utm_rf_company_name"

      },

       Address: {

         channel: "query",

         selector: "utm_address"

      },

       State: {

         channel: "query",

         selector: "utm_state"

      },

       City: {

         channel: "query",

         selector: "utm_city"

      },

       Postal_Code: {

         channel: "query",

         selector: "utm_postal_code"

      },

   };

         

   /* --- NO NEED TO EDIT BELOW THIS LINE! --- */

   var currentCookies = FormsPlus.util.Cookies.get(),

       currentQuery = FormsPlus.util.URI.URI().search(true);

 

   var hiddenFields = Object.keys(hiddenFieldMap)

         .reduce(function(acc, field) {           

           var fieldDescriptor = hiddenFieldMap[field];

          

           switch (fieldDescriptor.channel) {

             case "cookie":

               acc[field] = currentCookies[fieldDescriptor.selector];

               break;

             case "query":

               acc[field] = currentQuery[fieldDescriptor.selector];

               break;

             case "constant":

               acc[field] = fieldDescriptor.selector;

               break;            

           }

           return acc;

         }, {});

   form.addHiddenFields(hiddenFields);

});

      </script>

Can you help this when you have moment?

I really appreciate it.

SanfordWhiteman
Level 10 - Community Moderator

Re: Cookie hidden fields don't work if custom html is used for known visitors

If all the other fields are working, check to see in Admin >> Field Management that you aren't deliberately blocking updates to those 2 fields.

Shonal_Narayan2
Level 1

Re: Cookie hidden fields don't work if custom html is used for known visitors

Hi Sanford,

Thanks for the reply. But, none of the hidden fields are being blocked from updating. ..

SanfordWhiteman
Level 10 - Community Moderator

Re: Cookie hidden fields don't work if custom html is used for known visitors

Have you done as I said in the second response?