Using the form's default on a Form 2.0 embedded form

Robb_Barrett
Marketo Employee

Using the form's default on a Form 2.0 embedded form

Curious how I'd do this:

Let's say I have a form with a hidden field of Country, which on the form defaults to United States.  The code to embed and run the form is on my LP template.  The correct form is chosen by a token so I don't know whether or not I'll be asking the Country question.

If the lead is known and has a lead.Country value, I'd like to defaul to that value. If the lead is unknown, I'd like to default to United States.  How do I modify my form.vals() in the code to choose the default option on the form itself? Some forms using this template might be Canadian and I may want to default them there instead of United States.

Robb Barrett
Tags (3)
5 REPLIES 5
SanfordWhiteman
Level 10 - Community Moderator

Re: Using the form's default on a Form 2.0 embedded form

Will the Country be originally entered by the lead in that same browser? If so, save it to localStorage onSuccess, then fetch it out in a subsequent form's whenReady.  (You could use cookies, but localStorage is way easier unless you absolutely need to share across a parent domain.)

Robb_Barrett
Marketo Employee

Re: Using the form's default on a Form 2.0 embedded form

No clue.  And I don't know that I'll be giving them the opportunity to enter it. I also can't guarantee that other people will remember to put Country on their forms, so it's also possible that a lead could be created without a country code.

I'm starting to think that putting the form on the field is the only option.

Robb Barrett
SanfordWhiteman
Level 10 - Community Moderator

Re: Using the form's default on a Form 2.0 embedded form

Sounds like the "self-hiding field" pattern: a field that's hidden if it has a value, shown if empty.

There's a demo here: MktoForms2 :: Self-Hiding Field

In the demo, the fields Country and LastName are both set to self-hide.  If they have previously filled values, their form widgets will not be shown.

Robb_Barrett
Marketo Employee

Re: Using the form's default on a Form 2.0 embedded form

Is a default field possible?  Can I have like "field":"{{lead.field}}":"DefaultValue"??

Robb Barrett
SanfordWhiteman
Level 10 - Community Moderator

Re: Using the form's default on a Form 2.0 embedded form

Only if you were also using Prefill and/or a Marketo LP, since the token will not be replaced.