Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

CountryDropdownField Default Country

Go to End

4 Posts   3544 Views


Community Member, 10 Posts

30 December 2010 at 4:15pm


I'm trying to build a custom form for a page with a country dropdown and I can't get it to show the country I want selected rather than just the first entry.

new CountryDropdownField(
     $name = 'Country',
     $title = 'Country',
     $value = 'US'

I noticed the the API I can call $isSelected but I not sure where/how to implement this. The userforms module now has a country dropdown but again I cant see where to set the default country.



Forum Moderator, 5523 Posts

1 January 2011 at 6:14pm

Having a quick look at the API for the field the constructor states that the default value is the 4th argument rather than the 3rd which could be the solution. You may also want to disable the defaultToVisitorCountry check if GeoIP doesn't work.


Community Member, 10 Posts

4 January 2011 at 1:20pm

Thanks Willr, I got both my custom forms and userforms working correctly now.


Community Member, 15 Posts

8 March 2013 at 11:11am

Just found this post and have done this in SS3.0.4 as below, might be useful for others..

static $db = array(
'BirthPlace' => 'Varchar(255)'
static $default_country = 'AU';

public function getCMSFields() {
$fields = parent::getCMSFields();
$fields->addFieldToTab('Root.Main',new CountryDropdownField('BirthPlace', 'Birth Place'));
return $fields;