Solved! Go to Solution.
.
The script is this one. The added code beyond Marketo's usual Embed Code is in yellow. Note that 1429 is the form ID (you have to change this every time) and 300-GEQ-584 is specific to our instance of Marketo, so change that too if you're using this.
<script src="//app-sj05.marketo.com/js/forms2/js/forms2.js"></script> <form id="mktoForm_1429"></form> <script>MktoForms2.loadForm("//app-sj05.marketo.com", "300-GEQ-584", 1429, function() {
$("#mktoForm_1429 [name='uRLofMostRecentFormFill']").val( location.pathname );
});</script>
Hi Matt,
I'm also trying to capture the full URL and am wondering how and where you added the code above? When building landing pages, I am unable to edit the Embed Code. I also cannot edit the Embed Code in Design Studio for the particular form that needs to capture the URL from a hidden field.
You don't need to edit the embed code. Use the MktoForms2.whenReady event. This works on both Marketo and non-Marketo LPs.
MktoForms2.whenReady(function(form){
form.addHiddenFields({ last_form_fill_url : document.location.href });
});
Obviously substitute the actual name of the field in your instance for last_form_fill_url.
Note the code in the earlier post has a bug and should not be used. Forms 2.0 provides the setValues and addHiddenFields methods to set field values accurately on the form object (not just inputs in the <FORM> element). You should not set values on the input element directly: it will not work for all field types and form configs.
Hi,
Still not sure where to add this:
"MktoForms2.whenReady(function(form){
form.addHiddenFields({ last_form_fill_url : document.location.href });
});"
Also, this exact question was answered on another zombie thread today: Want to populate a field that has the actual URL a web form is filled out on.