For our Marketo Landing Pages with Forms on them we want to capture what webpage url the form was filled out on. {{trigger.Web Page}} does not work because that only give the Marketo description name. We need the full url of the Landing Page. How can we do this?
Solved! Go to Solution.
Hi there, is there a way to implement this script on the form itself?
Yes, but I wouldn't recommend it. See my thoughts on this other thread from just today: Is it okay to use javascript in rich text fields in forms?
Sanford I think you can help me out.
I'm looking at creating a global form for gated content and using the URL to route users to the correct content.
I may be in a bit over my head right now, but maybe you can help me out.
I placed the below into a RT field in the form... based on this thread
<script>
MktoForms2.whenReady(function(form){
form.addHiddenFields({"Latest_Form_Fill_Webpage":document.location});
})
</script>
I'm pretty sure my implementation is wrong for a few reasons.
1. when I save the RT field, marketo automatically adds to the code //[Cdata! ....
2. I think Mkto.Forms2.whenReady() only runs on submit? I'm not sure and don't know where to find documentation right now.
Thoughts?
Should I avoid using the JS in the Form Rt and just implement in the footer of all my wordpress pages + MKTO landing page templates?
I'm looking at creating a global form for gated content and using the URL to route users to the correct content.
If you're not using the field outside of the form context, you already have the {{trigger.web page}} to work with, so be sure you need to save the value before you do this at all.
form.addHiddenFields({"Latest_Form_Fill_Webpage":document.location});
Use document.location.href if you want a string. Even if document.location works because it gets toString()'d, it's not good to depend on that.
1. when I save the RT field, marketo automatically adds to the code //[Cdata! ....
That's fine, it's an old-fashioned compatibility hack that isn't necessary but it isn't affecting the code.
2. I think Mkto.Forms2.whenReady() only runs on submit? I'm not sure and don't know where to find documentation right now.
whenReady runs when the form is ready for use, not only on submit. It can be used to add onSubmit listeners but the whenReady function itself will run immediately. whenReady is the right place for what you're doing. See http://developers.marketo.com/javascript-api/forms/
Should I avoid using the JS in the Form Rt and just implement in the footer of all my wordpress pages + MKTO landing page templates?
If you only have one global form, you can keep it in the RT Area. The disadvantage (or advantage depending on your angle) is that you have to reapprove the form to make changes to the form behaviors. This means also reapproving Marketo-hosted LPs.
Many Thanks! Going to take a dive into this soon and I'll report back.
Thanks for the support!
Global form is live and logic for thank you page is implemented based on the custom field filled by the JS.
In my case looks like I ran into issues because the field had a different syntax when looking at the API convention.
You'll need to use a script to populate this field, something like this:
<script>
MktoForms2,whenReady(function(form){
form.vals({"yourFieldApiName":document.location});
})
</script>
This will add the URL of the page into the specified field, yourFieldApiName.
Hi Kenny. I am not a developer. Where would I specifically add this script? Thanks!
You can just add an HTML block to your page and input the script there. The block should be ordered after your form.
This would just be the Marketo Landing Page template HTML correct?
No the page itself, not the template, unless you want this behavior to occur with all forms on pages based on that template.
Hello again Kenny. Below is my script I added as an HTML block and it is below the form block. For some reason it isn't populating that custom field.
<script>
MktoForms2,whenReady(function(form){
form.vals({"Latest_Form_Form_Webpage__c":document.location});
})
</script>
It's MktoForms2.whenReady (period, not comma).
Hi Sanford. I made that switch and it still does not work. Any ideas?
Post a link to your page so I can see the JS console. Hard to know without that.
http://pages.hexarmor.com/rig-lizard-2021.html
Thanks Sanford
Actually, our bad, do
form.addHiddenFields
not
form.vals
Does this script have the option to be used globally on all webpages, or do we have to individually add to each webpage with a form?
You can add it to all webpages as long as you pre-check if the forms library exists:
window.MktoForms2 && MktoForms2.whenReady(function(form){
form.addHiddenFields({"Latest_Form_Form_Webpage__c":document.location.href.split('?')[0]});
});
You guys are awesome! It worked. I have one more thing. Is there anyway to remove UTM parameters so it is a bare URL?