Skip to main content
Dan_Stevens_
Level 10
October 22, 2013
Question

Unable to retrieve URL parameter in hidden form field

  • October 22, 2013
  • 9 replies
  • 2473 views
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?
This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

9 replies

October 22, 2013
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
October 22, 2013
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?


Dan_Stevens_
Level 10
October 22, 2013
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
October 23, 2013
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")

February 5, 2014
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
February 5, 2014
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:



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/collaboration.aspx



February 5, 2014
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
February 5, 2014
Yes, that's it.  Are you using the legacy forms or forms 2.0?
February 5, 2014
You got it! forms 2.0 did not work but a legacy style form did! thanks