Re: Unable to retrieve URL parameter in hidden form field

Subscribe
Dan_Stevens_
Level 10 - Champion Alumni
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
You got it! forms 2.0 did not work but a legacy style form did! thanks
Dan_Stevens_
Level 10 - Champion Alumni
Yes, that's it.  Are you using the legacy forms or forms 2.0?
Anonymous
Not applicable
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
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
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
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")

Dan_Stevens_
Level 10 - Champion Alumni
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
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
Anonymous
Not applicable
A short JavaScript can obtain the page hosting the iFrame.

parent.document.location.href or parent.window.document.location would be suitable optiions.