Passing URL parameters to a visibile Marketo form field

Anonymous
Not applicable

Passing URL parameters to a visibile Marketo form field

Hi all,

I am trying to figure out the JavaScript needed to pass a URL parameter into a visibile marketo form field on the page. For example, http://company.com/test.html?code=123 would pass 123 into the Code form field on that page. Any ideas? I found one post on it, but the link to the solution doesn't work! Any advice would be greatly appreciated.

Thanks Katie
Tags (1)
3 REPLIES 3
Anonymous
Not applicable

Re: Passing URL parameters to a visibile Marketo form field

You don't need any extra JS for this if you use a hidden field - is there a reason why you want to make this field visible?  Perhaps, you could capture two values - one in a hidden field and another one which is from the visible field/user input.  


Just follow the instructions in the section titled "Set a Hidden Form Field from a URL Parameter" at https://community.marketo.com/MarketoArticle?id=kA050000000KyqoCAC


Anonymous
Not applicable

Re: Passing URL parameters to a visibile Marketo form field

There are circumstances visible fields make sense. 
 
You can use a short jQuery to gather URL parameters and populate any field, no matter it is visible or not.
 
 
View the page source to find the field ID for each getQueryString. It just requires one variable to read the URL parameter and one instruction to set the field value.
 
Robb_Barrett
Marketo Employee

Re: Passing URL parameters to a visibile Marketo form field

Bumping.

I'm trying to do the same thing.  I'm making a double-opt in based off of an email.  
  • The recipient gets the email and clicks a link.  
  • The link has two parameters: CPSRefSiteEmail and CPSRefSiteName.
  • They get to a page with a form that will display the values and ask them to hit Submit to verify they made a correct selection.
I've made a form with the two fields on it.  I've made a Landing Page with the form embedded.  I've added a Custom HTML box with the following script:

<script language="Javascript" src="/js/public/jquery-latest.min.js" type="text/javascript"></script>
<script src="/js/public/jQueryString-2.0.2-Min.js" type="text/javascript" ></script>
 
<script>
  // to set cookies.  Uses noConflict just in case
  var $jQ = jQuery.noConflict();
  var pCPSRefSiteName = $jQ.getQueryString({ ID: "CPSRefSiteName" });
document.getElementById("CPSRefSiteName").setAttribute("value", pCPSRefSiteName);
</script>

<script language="Javascript" src="/js/public/jquery-latest.min.js" type="text/javascript"></script>
<script src="/js/public/jQueryString-2.0.2-Min.js" type="text/javascript" ></script>
 
<script>
  // to set cookies.  Uses noConflict just in case
  var $jQ = jQuery.noConflict();
  var pCPSRefSiteEmail = $jQ.getQueryString({ ID: "CPSRefSiteEmail" });
document.getElementById("CPSRefSiteEmail").setAttribute("value", pCPSRefSiteEmail);
</script>

When I enter the URL along with one of the parameters and a value, I get nothing in the boxes.  What am I doing wrong?  I've also tried replacing the ID: with the integer instead of the field name and nothing worked.

Can I get a more complete explanation?
Robb Barrett