Re: Unable to retrieve URL parameter in hidden form field

Dan_Stevens_
Level 10 - Champion Alumni

Unable to retrieve URL parameter in hidden form field

On our site's Contact-Us form, I've included a hidden form field to retrieve the URL of the page a user was visiting prior to clicking on the "contact us" link (the link includes a "?ref=[url of referring page]" parameter.  We are using a Marketo form with an iframe on our site's contact us page.  I've setup the form properly using the instructions here (http://community.marketo.com/MarketoArticle?id=kA050000000KyqoCAC) - using a parameter name of "ref".  But when I test the page, only the default value is populating the hidden form field - not the actual "ref" value.  Can this not be done when using an iframe-embedded form/landing page?
Tags (1)
9 REPLIES 9
Anonymous
Not applicable

Re: Unable to retrieve URL parameter in hidden form field

A short JavaScript can obtain the page hosting the iFrame.

parent.document.location.href or parent.window.document.location would be suitable optiions.
Dan_Stevens_
Level 10 - Champion Alumni

Re: Unable to retrieve URL parameter in hidden form field

Thanks.  Would I retrieve this directly in the hidden "ref" field or define it within the parent page that hosts the iframe?  Would I still use this to properly define that value?

0EM50000000QPCN.jpg
Dan_Stevens_
Level 10 - Champion Alumni

Re: Unable to retrieve URL parameter in hidden form field

I came across this article in the community: https://community.marketo.com/MarketoArticle?id=kA050000000L55PCAS.  It appears the customization would be done here:

var sourceParam = getUrlVars(url)["source"];
    $("#LeadSource").val(sourceParam);

Could someone advise as to what values I would use for “source” and “#LeadSource”?  I’m assuming one of these would be “ref”
Dan_Stevens_
Level 10 - Champion Alumni

Re: Unable to retrieve URL parameter in hidden form field

I figured out the solution with the help of our Marketo support rep.  Here are the values to use:
  • source: name of the URL parameter (in our case, it's "ref" - without the quotes)
  • #LeadSource - "#" + name of the API name of the field (in our case, it's "#Referral_URL")

Anonymous
Not applicable

Re: Unable to retrieve URL parameter in hidden form field

Hi Dan - the link to the help article is gone. can you tell me where you put the script and exactly how it was added? in the Marketo lp or within the iframe tag or just on the page hosting the iframe form?
Dan_Stevens_
Level 10 - Champion Alumni

Re: Unable to retrieve URL parameter in hidden form field

This is so frustrating when references to prior posts are no longer available - I wish Marketo would address this issue.  Anyway, the script is place on the Marketo landing page (where the form is placed) - and that page is what is referenced in the iframe of our website.  The full script is as follows:

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<!-- Keep your jQuery up to date -->

<script>

  $(function(){
    var url = (window.location != window.parent.location) ? document.referrer: document.location;
    var sourceParam = getUrlVars(url)["ref"];
    $("#Avanade_Referral_URL").val(sourceParam);
  })

  function getUrlVars(url) {
    var vars = [],
        hash;
    var hashes = url.slice(url.indexOf('?') + 1).split('&');
    for (var i = 0; i < hashes.length; i++) {
        hash = hashes[i].split('=');
        vars.push(hash[0]);
        vars[hash[0]] = hash[1];
    }
    return vars;
  }

</script>

And here's our hidden form field values:
0EM50000000RQuC.jpg


and finally, here's the actual page on our site with the 'ref' parameter defined:
http://www.avanade.com/en-us/pages/contact.aspx?ref=http://www.avanade.com:80/en-us/services/pages/c...



Anonymous
Not applicable

Re: Unable to retrieve URL parameter in hidden form field

Is this the article? https://community.marketo.com/MarketoResource?id=kA650000000GuKCCA0

thanks - this looks good... but my form is not submitting now. just gets stuck after I hit the button. 
Dan_Stevens_
Level 10 - Champion Alumni

Re: Unable to retrieve URL parameter in hidden form field

Yes, that's it.  Are you using the legacy forms or forms 2.0?
Anonymous
Not applicable

Re: Unable to retrieve URL parameter in hidden form field

You got it! forms 2.0 did not work but a legacy style form did! thanks