0151 355 4555

International Forms

PredictiveAddress includes data from multiple countries, and the user can select which country they want to use. However, it is useful to provide them with a helpful default.

The default country selection is based on two settings, initialCountry and fallbackCountry.

The initialCountry setting specifies which country is selected by default. This can be set as an ISO standard 2-character country code, e.g. "GB" or "US", or it can be set to "auto".

If it is set to "auto", the default country is determined based on the user's IP address, utilising our Country Detection service. Note that you must have credits for the Country Detection service for this to work.

If the automatically detected country is one that is not currently supported by PredictiveAddress, the country specified by the fallbackCountry setting is used. This should be set to an ISO standard 2-character country code.

Separate Country Field

If your form has a drop down list to contain the country of the address, this can be connected to the PredictiveAddress control by including an entry in the fields configuration section:

<script type="text/javascript" src="https://webservices.data-8.co.uk/javascript/predictiveaddress.js"></script>

<script type="text/javascript">

$('#address1').predictiveaddressui({
	// Change this to your own Ajax key
	ajaxKey: 'your-ajax-key',
	fields: [
		{ element: 'address1', field: 'line1' },
		{ element: 'address2', field: 'line2' },
		{ element: 'address3', field: 'line3' },
		{ element: 'city', field: 'town' },
		{ element: 'county', field: 'county' },
		{ element: 'postcode', field: 'postcode' },
		{ element: 'countrylist', field: 'country' }
	]
}).show();

</script>

In this example, PredictiveAddress will take the default country from the selected value in the drop down list with the ID "countrylist". When an address is selected, the country that address is in will be selected in that drop down list.

By default this assumes the value of the items in the drop down list are the associated ISO 2-character codes. This can be changed to be the country name by specifying the countryFieldFormat advanced option:

<script type="text/javascript" src="https://webservices.data-8.co.uk/javascript/predictiveaddress.js"></script>

<script type="text/javascript">

$('#address1').predictiveaddressui({
	// Change this to your own Ajax key
	ajaxKey: 'your-ajax-key',
	fields: [
		{ element: 'address1', field: 'line1' },
		{ element: 'address2', field: 'line2' },
		{ element: 'address3', field: 'line3' },
		{ element: 'city', field: 'town' },
		{ element: 'county', field: 'county' },
		{ element: 'postcode', field: 'postcode' },
		{ element: 'countrylist', field: 'country' }
	],
	countryFieldFormat: 'name'
}).show();

</script>

Limiting Countries

By default the PredictiveAddress script will allow the user to select from a list of all our available countries. However, you may wish to restrict this list in some way, perhaps because you only deliver to a certain country or can't deliver to specific excluded countries. We facilitate these two approaches using the allowedCountries and barredCountries settings.

To allow the user to select only countries that you explicitly allow, supply the ISO 2 character codes for those countries as the allowedCountries setting, e.g.

 

<script type="text/javascript" src="https://webservices.data-8.co.uk/javascript/predictiveaddress.js"></script>

<script type="text/javascript">

$('#address1').predictiveaddressui({
	// Change this to your own Ajax key
	ajaxKey: 'your-ajax-key',
	fields: [
		{ element: 'address1', field: 'line1' },
		{ element: 'address2', field: 'line2' },
		{ element: 'address3', field: 'line3' },
		{ element: 'city', field: 'town' },
		{ element: 'county', field: 'county' },
		{ element: 'postcode', field: 'postcode' }
	],
	allowedCountries: [ 'GB', 'US' ]
}).show();

</script>

This would allow the user to only select United Kingdom or United States from the country list. If only one country is allowed the country selector will not be shown at all.

To allow the user to select from any of our supported countries except specific exclusions, use the barredCountries setting instead, e.g.

<script type="text/javascript" src="https://webservices.data-8.co.uk/javascript/predictiveaddress.js"></script>

<script type="text/javascript">

$('#address1').predictiveaddressui({
	// Change this to your own Ajax key
	ajaxKey: 'your-ajax-key',
	fields: [
		{ element: 'address1', field: 'line1' },
		{ element: 'address2', field: 'line2' },
		{ element: 'address3', field: 'line3' },
		{ element: 'city', field: 'town' },
		{ element: 'county', field: 'county' },
		{ element: 'postcode', field: 'postcode' }
	],
	barredCountries: [ 'AU' ]
}).show();

</script>

This would prevent the user from selecting Australia from the country list, but would allow any of our other supported countries without having to list them all individually.