Autofill email field via URL

Highlighted

Autofill email field via URL

Not sure how to explain this but here goes:

We're currently using an email sign-up method that requests the email address on a page then fills it in on the actual form field using the following:

URL?email=test@test.com

When submitted the browser opens the actual form and the email is automatically filled in and the user must fill in the rest of the form.

We're testing using a Marketo form instead so I'm wondering if there's a similar syntax?

6 REPLIES 6
Highlighted
Level 10 - Champion Alumni

Re: Autofill email field via URL

images?

why are you doing this?

Highlighted

Re: Autofill email field via URL

Screen Shot 2018-03-12 at 11.49.42 AM.png

^ This box is on the page. The user enters their email and then hits submit.

Screen Shot 2018-03-12 at 11.49.51 AM.png

^ This is the form the submit button takes you to. See the email is already filled in the field.

In the interest of not derailing the purpose of this thread, I'm not going to go into why. I appreciate your interest in helping tho, Josh.

Highlighted
Level 10 - Community Moderator

Re: Autofill email field via URL

MktoForms2.whenReady(function(form){

  form.setValues({ Email : decodeURIComponent(document.location.search.substring(1)) });

});

Put this is in a <script> anywhere after the <script> that loads forms2.min.js.

This assumes the entire querystring is the email address. If there are other query parameters as well, the code is more complex.

Highlighted

Re: Autofill email field via URL

Thanks Sanford. Unfortunately, we're unable to edit the code on the page for this project. I was hoping for something we could do on the Marketo side to accept the parameter.

Highlighted
Level 10 - Community Moderator

Re: Autofill email field via URL

Marketo can automatically transfer query parameters into Hidden fields. It doesn't do this for Visible fields without an assist from JS.

If you absolutely can't edit the surrounding page, you can add the script in a Rich Text area on the form. I normally advise strongly against this as it's easy to lose track of such code.

pastedImage_0.png

Highlighted

Re: Autofill email field via URL

Thanks for this!
Helped me to populate the autofill for my unsubscribe.