Cognito-forms – How to set default values for address fields in Cognito Forms

cognito-forms

How can I make the default country as India, default state as West Bengal and city as Kolkata in a Cognito form?

Best Answer

I'm part of the support team here at Cognito Forms.

In order to do this, your first step would be to mark your Address field as "International" within the Field Settings, then save.

Next, you'll need to use your embed code. The last line before the end of the <div> tag should currently look something like this:

<script>Cognito.load("forms", { id: "50" });</script>

What you'll need to do is use this line of the embed code to add field targeting so you can set a default value. After your form's unique ID number, you'll need to add a comma, then space, then the following:

entry:{Address:{City:"DEFAULT", State:"DEFAULT", PostalCode:"DEFAULT", Country:"India"}}

With each of the three DEFAULT words being the actual values you want to preset.

So your whole line of code should look like this:

<script>Cognito.load("forms", { id: "50", entry:{Address:{City:"DEFAULT", State:"DEFAULT", PostalCode:"DEFAULT", Country:"India"}}});</script>

Just be sure to use your actual embed code so the form ID is correct.