SOLVED

Auto populate Country

Go to solution
Callum_Pirie
Level 3

Auto populate Country

We have a bunch of forms on our website and have a dropdown list as below:

form1.png

form2.png

and in the backend of the form builder is as follows

country.png

We have a country selector for the website which then localizes the pages as per country (ie. en-gb, en-us)

Is there anyway with the current setup to make it so the same form if on en-gb defaults the country selector as United Kingdom (however giving the user the option to change country if needed) and if on en-us to default to United States

Is this possible?

We do have gaconnectors for cookies within countries could we do something around this?

gaconnector.png

Thanks

1 ACCEPTED SOLUTION

Accepted Solutions
SanfordWhiteman
Level 10 - Community Moderator

Re: Auto populate Country

It's absolutely possible to do this, but not exactly in the way you describe.

You don't want Country to be a Hidden field because then it will never be user-editable.

Instead, add an additional Hidden field that stores the session-wide locale value. Name that field like LastSessionLocale and Auto-Fill it from the corresponding cookie.

Then using the Forms 2.0 JS API, map the Country value from LastSessionLocale. I can help with that part if you set up the first part.

Note: if the session locale is saved in a cookie, you may have an order-of-operations issue if everything happens on the same page. That is, if the form renders on a page, and then the person clicks the (non-form) dropdown to choose their locale and the page doesn't immediately refresh, then the Country on the already-shown form will not be updated (as the cookie did not exist at the moment the form was drawn).  Of course since JS will have been used to set the cookie in this case, it could also have set the Country at the same time -- but that part of the JS isn't going to be modifiable by us, you'd have to talk with your main web team.

View solution in original post

8 REPLIES 8
SanfordWhiteman
Level 10 - Community Moderator

Re: Auto populate Country

It's absolutely possible to do this, but not exactly in the way you describe.

You don't want Country to be a Hidden field because then it will never be user-editable.

Instead, add an additional Hidden field that stores the session-wide locale value. Name that field like LastSessionLocale and Auto-Fill it from the corresponding cookie.

Then using the Forms 2.0 JS API, map the Country value from LastSessionLocale. I can help with that part if you set up the first part.

Note: if the session locale is saved in a cookie, you may have an order-of-operations issue if everything happens on the same page. That is, if the form renders on a page, and then the person clicks the (non-form) dropdown to choose their locale and the page doesn't immediately refresh, then the Country on the already-shown form will not be updated (as the cookie did not exist at the moment the form was drawn).  Of course since JS will have been used to set the cookie in this case, it could also have set the Country at the same time -- but that part of the JS isn't going to be modifiable by us, you'd have to talk with your main web team.

Callum_Pirie
Level 3

Re: Auto populate Country

Thanks Sanford,

Im not that familiar with Marketo at all so im worried I might be setting this up incorrectly.

The other point I forgot to mention which could make things more tricky is we have Marketo linked to Salesforce. So if someone fills a form out via marketo and its a score of 200+ it gets pushed through to SF and i feel like these changes might effect what is shown in SF.

Sorry for wasting time

SanfordWhiteman
Level 10 - Community Moderator

Re: Auto populate Country

Im not that familiar with Marketo at all so im worried I might be setting this up incorrectly.

I don't think so -- none of what you've said sounds particularly off-base. You're trying to wire together 2 preferences, both of which were user-specified (i.e. not automatically detected), in order to ease the UX. Nothing wrong with that.

So if someone fills a form out via marketo and its a score of 200+ it gets pushed through to SF and i feel like these changes might effect what is shown in SF.

SFDC doesn't have any impact on what we're talking about here.

Callum_Pirie
Level 3

Re: Auto populate Country

Hi Sanford,

thanks for this - so forgive me , not familiar at all with Marketo..

111.png

Would I just create a hidden field like this and call it LastSessionLocale

​and then you would help setup the rest?

SanfordWhiteman
Level 10 - Community Moderator

Re: Auto populate Country

Yes.

Is this really a locale (en-us, fr-ca) or just a language?

How closely does it map to the Country options?

Callum_Pirie
Level 3

Re: Auto populate Country

It was all setup before I came onboard but im 99.9% sure its locale.. the user goes to the website www.digitalmarketinginstitute.com and it detects your IP and suggests to change to the local version the only differences really are American vs British English and the pricing.

The country options are highly important as this means the correct sales rep gets assigned the lead through Marketo and then Salesforce.

SanfordWhiteman
Level 10 - Community Moderator

Re: Auto populate Country

OK, in any case set up the corresponding Hidden field to pick up from that cookie and we'll work from there.

Iva_Kanova
Level 2

Re: Auto populate Country

Hi Sanford, I am trying to do something similar but with a product, instead of a country. I am using the field uTMMedium as hidden and autofilled based on the utm_medium URL parameter, and I want the value that gets populated in that field to show up in the field productModel. Is there any chance you can help me with the Javascript? I tried using the one you provided in this tread (https://nation.marketo.com/t5/Product-Discussions/Form-drop-down-field-auto-fill-on-external-website...) but it doesn't seem to work. I included the correct field names but maybe I placed the code in the wrong spot. I am using a Marketo landing page for the form, not an external website.

I look forward to any feedback 🙂 thank you in advance!