I'm trying to add Javascript that pulls Original External Referrer Url into a hidden form field. This is the Javascript that I will be using (from this discussion😞
Do I need to place this script on the landing page or in the form somewhere? If on the form, where do I place this?
Solved! Go to Solution.
Yes, if that's the real field name, then the field name in addHiddenFields() needs to be Original_External_Referrer__c.
form.setValues() is for when the field has been added to the form in Form Editor (there's no reason for it to be on the form if it will only be hidden and populated via JS).
So you want form.addHiddenFields(), not form.setValues().
The <script> with special form behaviors code can be placed in a Rich Text area on the form, but you may find that difficult to manage. You will probably find it easier to put it on the LP directly. Make sure it comes after the <script> that loads forms2.min.js.
Hey Sanford,
Thanks for the reply! I am adding the script to the LP template in the script in the header. However, It is not filling the hidden field upon form fill out. This is what the script looks like:
<script src="http://info.healthyvending.com/rs/018-NMA-932/images/snacknation_jquery_min.js">
MktoForms2.whenReady(function(form){
form.addHiddenFields({
OriginalExternalReferrer : document.referrer
});
});
</script>
Any suggestions? Am I placing the code in the wrong place?
Any suggestions? Am I placing the code in the wrong place?
Hmm, yes...
You can't put code inside a <script> block that has a remote src= (well, you can put text in there, but that is for obscure use cases that are irrelevant here).
You want a separate <script></script> block. No src. You will likely find this easiest to place right before the closing </body> tag (not in the <head>.
Placed it in the code with still no luck. This is what I added to the preexisting script right before the </body> tag
<!--scripts starts here-->
<script>
MktoForms2.whenReady(function(form){
form.setValues({
OriginalExternalReferrer : document.referrer
});
});
</script>
<script type="text/javascript" src="http://info.healthyvending.com/rs/018-NMA-932/images/snacknation_general.js"></script>
<!--scripts ends here-->
Any suggestions regarding the above?
As an alternative, where would I add the code in an individual form?
Please post a link to the URL where you've deployed this.
But it is working. How are you testing?
Click the first link on this page . The link is "The Millennial generation".
After clicking that link and being driven to the landing page, the "Original External URL" hidden field should be filled with the referring URL, which is From Healthy Food Subscription to Snack Products: 10 Brands that Give Back | SnackNation, correct?
Ok, I tested and it looks like it is working (see below),
However, it is not populating the field in Marketo,
The field is the following,
Original_External_Referrer__c | Original External Referrer |
Do I need to change something in the script to push the field into Marketo?