We would like to capture and store the most recent page url (from which the lead filled out the form in a Marketo field). Does anyone have the script for the same?
Solved! Go to Solution.
Thanks a lot @SanfordWhiteman 🙂
Could you provide the complete script please and also tell us how to implement it on both external as well as Marketo landing pages (Guided template)
I assumed we need to add some more code to the below:
MktoForms2.whenReady(function (form) {
form.addHiddenFields({ LastFormURL : document.location.href });
});
No, that's the code. There's nothing else.
Simply make sure that code runs after the embed code. On non-Marketo pages: put it anywhere after the embed code (since you control placement). On Marketo LPs: put it just above the closing </body> tag.
Thanks @SanfordWhiteman , You are awesome!!!!
So just confirming we just have to add the below code on the page and just add the hidden field in the form by the name 'LastFormURL' (keep the autofill option to use default value and leave it blank)..
<script>
MktoForms2.whenReady(function (form) {
form.addHiddenFields({ LastFormURL : document.location.href });
});
</script>
... just add the hidden field in the form by the name 'LastFormURL' (keep the autofill option to use default value and leave it blank)..
No, you don't have to add the hidden field in Form Editor at all. The JS takes care of everything.
@SanfordWhiteman : I created the Url form field (LastFormURL) and also added the below script as suggested on the test page but the page url is not getting captured in the new field after filling out the form. Could you help please - http://au-sn01.marketo.com/lp/987-YUV-596/lastformurl-testing.html
<script>
MktoForms2.whenReady(function (form) {
form.addHiddenFields({ LastFormURL : document.location.href });
});
</script>
It's adding the field as expected, as you can see if you inspect the page:
Make sure in Admin » Field Management that the SOAP name of the field is correct. (Export the field names and check the resulting spreadsheet.)
Thanks @SanfordWhiteman 🙂
Actually just noticed that API name of the field is lastFormURL ('l' in lowercase) . As per my knowledge we would not be able to update the API name of a field once it is created so I updated the field name (API name) in the script. I assume we need to provide the API name instead of the field name in the script?
<script>
MktoForms2.whenReady(function (form) {
form.addHiddenFields({ lastFormURL : document.location.href });
});
</script>
It is working now :), do we need to keep the type of field as string or will url type field will also work?
If that's the SOAP API name, yes.
P.S. Please use the syntax highlighter (Insert/Edit code sample) when posting code. Each time you paste your code in as unformatted text, I've been editing your post for you and leaving you a note.