Has anyone had any luck populating a form field with a URL parameter on a Marketo landing page?

Anonymous
Not applicable

Has anyone had any luck populating a form field with a URL parameter on a Marketo landing page?

I'm trying to use a query value in a URL to populate the value (some of the time) on a non-hidden field.  Support has told me it's possible but that I need custom code to set these values and I'm certainly not a developer.

Any examples that have worked for other people would be super helpful. It's just one field to determine an event city based on the link that is clicked on the prior page that I want to set.

Thanks!
Tags (1)
5 REPLIES 5
SanfordWhiteman
Level 10 - Community Moderator

Re: Has anyone had any luck populating a form field with a URL parameter on a Marketo landing page?

The goal should be to take advantage of Marketo's existing auto-fill capability, but reveal the field in the browser for further editing.  This is far easier than -- by counterexample -- using regular fields and then having to rewrite the code to read from cookies and URL params.

So here is a demo where you let Marketo set values on the hidden field as usual but then you unhide the field and inject it into the form (it is in fact dirt-simple to simply unhide the field -- one line of code -- but if you don't surround it with the standard label and wrapper HTML you will never get the layout you want).

The demo form reads the LN URL parameter and sets it as the default for the LastName field.

The only config you would need to change is at the top of the code -- the "Config section."

Good luck!
Anonymous
Not applicable

Re: Has anyone had any luck populating a form field with a URL parameter on a Marketo landing page?

I know this is a dumb question but do I copy the HTML or just the JS part when I click your example link? Also do I need to update form ID's as well? They aren't in the config section but having trouble getting this to work like it does in your example.

Thanks so much for the help!
SanfordWhiteman
Level 10 - Community Moderator

Re: Has anyone had any luck populating a form field with a URL parameter on a Marketo landing page?

Well, you'd need both sides, because you need the forms SCRIPT tag as well as the FORM tag as usual, then another SCRIPT tag with the call to load() and all the other stuff in it.
Anonymous
Not applicable

Re: Has anyone had any luck populating a form field with a URL parameter on a Marketo landing page?

Got it - I think I updated the right fields but still no dice and the hidden field isn't unhidden.  Here's the example page: https://learn.zenefits.com/zenefits-roadshow.html?city=NYC&promo=Bromwell

Does the code work on drop-down select fields? I used another one of the fields that was also a drop-down in the config section.
SanfordWhiteman
Level 10 - Community Moderator

Re: Has anyone had any luck populating a form field with a URL parameter on a Marketo landing page?

Your page is confusing -- it looks like a Marketo landing page with a form, but you are also doing the MktoForms2.loadForm(), which is for embedding on non-Marketo pages.

Please try to simplify to only one or the other.  If you use the built-in LP form support, you want to do the form setup code inside
 
MktoForms2.whenReady( function(form){ ... } )

if you use the embedded form, you setup inside
 
MktoForms2.loadForm( <instance>, <munchkin id>, <form id>, function(form){ ... } )

but not both!

Because the form setup is erratic/duplicated, the unhide code never actually executes (you can see an error in the console).

The unhide code as written only supports text fields, not SELECT fields.  There's a clear reason for this: there's no such thing as SELECT type=hidden (in HTML as well as in Marketo).  When you switch a field to type=hidden, it behaves as if it were a INPUT type=text, only not visible. So out-of-the-box I couldn't just unhide the text with all of the other choices in a dropdown, since Mkto doesn't send the other choices to the browser once you switch to hidden.

There is a of course a way to do this with a SELECT as well, not incredibly difficult but kind of beyond my pro bono time right now... if you do feel like contacting me to get it done, feel free!