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

More important, you need to either

[a] copy the FormsPlus JS to your server and point to the URL

or

[b] point to the CDN URL https://cdpn-js.figureone.com/teknkl-formsplus-1.0.5.js

You can't hotlink to the demo the way you're doing now, you'll see this error if you look in your console:

pastedImage_1.png

It can't have been working at all if you were trying to load it from cdpn-dl.figureone.com.

Jayanto_Sukul_S
Level 2

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

Thanks Sanford Whiteman your JS code help me to tracked the hidden value on Known visitor form. It's perfectly work for me. Thanks for your contribution for the community.

Frank_Breen2
Level 10

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

Sanford Whiteman​, I'm using the solution above and all is working as expected, but we has a recent security audit and they flagged the following:

"They flagged a vulnerability that we have an outdated version of URI.js on the site. URI.js uses v1.18.0 and the newer version URI.js 4.2.2"

Any suggestions on how to update?

SanfordWhiteman
Level 10 - Community Moderator

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

*sigh*... "a vulnerability" as if they have any idea whether there's a security concern beyond "the version sounds old."

There's no vulnerability here. The embedded package is just not the very, very latest.

Frank_Breen2
Level 10

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

Thanks Sanford, this is why I reached out to get your 2 cents worth, I'll pass this on, I expected it was all good.

Craig_Boren
Level 2

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

Sanford Whiteman‌ - This is awesome! Thank you for this script. It worked perfectly!

One question - is there a way to set default utm_params with this script? For example, in the event that a return visitor comes to a page with Custom HTML set, and there are no utm parameters defined in the URL, we still want to attribute their visit with some type default utm params.

SanfordWhiteman
Level 10 - Community Moderator

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

Sure, will update later when I'm by my machine.

SanfordWhiteman
Level 10 - Community Moderator

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

OK Craig, you can set default values with the update at

    MktoForms2 :: KV HTML w/Auto-Fill and Cascade v1.1.0.

Just add multiple entries for a given field, in priority order from top to bottom.

In the demo, the field Field_With_Fallback is filled first from the query param, then falls back to the constant value if it's still empty.  (In fact I think I already had different demo code with this capability, but was too lazy to look for it.)

P.S. A Guaranteed Free Like to all people who can explain 2 reasons why you couldn't add duplicate fields (object keys) to the old code in the same way, in top to bottom order, even if the old code supported an ordered "cascade" of rules. 

Craig_Boren
Level 2

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

Very cool! This is great! Your new code is a little different from what I've used (based off of your older example). What would I need to do to add this new 'constant' value to my code? This is currently what I have on my landing page:

var hiddenFieldMap = {
UTM_Campaign__c: {
channel: "query",
selector: "utm_campaign"
},
UTM_Content__c: {
channel: "query",
selector: "utm_content"
},
UTM_Medium__c: {
channel: "query",
selector: "utm_medium"
},
UTM_Source__c: {
channel: "query",
selector: "utm_source"
},
UTM_Term__c: {
channel: "query",
selector: "utm_term"
}
};

/* --- 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);
SanfordWhiteman
Level 10 - Community Moderator

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

Can you highlight that JS using the Advanced Editor's syntax highlighter please?