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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

All other Modules /

Discuss all other Modules here.

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

Userform State Dropdown


Go to End


7 Posts   3400 Views

Avatar
Graphicator

Community Member, 62 Posts

8 January 2011 at 1:01am

Edited: 08/01/2011 1:02am

I added a Field for US States, and wondered where I can post this class for people in the US to add State dropdowns to their forms. Unless this is already included and i overlooked it.

moduledirectory/code/editor/EditableStateDropDown.php

class  EditableStateDropDown extends EditableFormField  {
	
		static $singular_name = 'State Field';
		
		static $plural_name = 'State Fields';

		
		function getFormField() {
			$labelField = new DropdownField($this->Name, $this->Title, GetStates::getStateDropDown());
			$labelField->addExtraClass('FormState'); 
			return $labelField;
		}

	}

moduledirectory/code/integration/GetStates .php

class  GetStates {
	
	protected static $us_stateCodes = array(
	'None Selected' => "Select",
	'Outside US' => "Outside US",
	'AL' => "Alabama",
	'AK' => "Alaska",
	'Alberta' => "Alberta",
	'AZ' => "Arizona",
	'AR' => "Arkansas",
	'Br. Columbia' => "Br. Columbia",
	'CA' => "California",
	'CO' => "Colorado",
	'CT' => "Connecticut",
	'DE' => "Delaware",
	'DC' => "District of Columbia",
	'FL' => "Florida",
	'GA' => "Georgia",
	'Guam' => "Guam",
	'HI' => "Hawaii",
	'ID' => "Idaho",
	'IL' => "Illinois",
	'IN' => "Indiana",
	'IA' => "Iowa",
	'KS' => "Kansas",
	'KY' => "Kentucky",
	'LO' => "Louisiana",
	'ME' => "Maine",
	'Manitoba' => "Manitoba",
	'MD' => "Maryland",
	'MA' => "Massachusetts",
	'MI' => "Michigan",
	'MN' => "Minnesota",
	'MS' => "Mississippi",
	'MO' => "Missouri",
	'MT' => "Montana",
	'NE' => "Nebraska",
	'NV' => "Nevada",
	'New Brunswick' => "New Brunswick",
	'NH' => "New Hampshire",
	'NJ' => "New Jersey",
	'NM' => "New Mexico",
	'NY' => "New York",
	'Newfoundland' => "Newfoundland",
	'NC' => "North Carolina",
	'ND' => "North Dakota",
	'Nova Scotia' => "Nova Scotia",
	'OH' => "Ohio",
	'OK' => "Oklahoma",
	'Ontaria' => "Ontario",
	'OR' => "Oregon",
	'PA' => "Pennsylvania",
	'Pr. Edward Isl.' => "Pr. Edward Island",
	'PR' => "Puerto Rico",
	'Quebec' => "Quebec",
	'RI' => "Rhode Island",
	'Saskatchewan' => "Saskatchewan",
	'SC' => "South Carolina",
	'SD' => "South Dakota",
	'TN' => "Tennessee",
	'TX' => "Texas",
	'UT' => "Utah",
	'VT' => "Vermont",
	'VA' => "Virginia",
	'WA' => "Washington",
	'WV' => "West Virginia",
	'WI' => "Wisconsin",
	'WY' => "Wyoming"
	);

	/** 
	 * Returns an array of  State Names
	 */
	static function getStateDropDown() {
		$dropdown = GetStates::$us_stateCodes;
		asort($dropdown);
		return $dropdown;
	}
}

Avatar
Willr

Forum Moderator, 5523 Posts

8 January 2011 at 8:27pm

I added a Field for US States, and wondered where I can post this class for people in the US to add State dropdowns to their forms. Unless this is already included and i overlooked it.

It is not already included. Not sure it's useful enough to be included in the default installation. Perhaps just keep it attached to the forum, you can optionally submit the field type as a module.

Avatar
Graphicator

Community Member, 62 Posts

8 January 2011 at 10:18pm

I added these userforms extension to my new github. Just learned how to commit + push changes today.
My additional custom fields are US States, and a Non Editable Field (with Default in the Extra Options)

https://github.com/graphicagenda/Extending-Silverstripe-Module--Userform/tree/

My question to Willr is, how do we call an image for the field, the one with the pencil... without uploading it into the main userforms module?

Avatar
Willr

Forum Moderator, 5523 Posts

9 January 2011 at 7:02pm

You can define a function getIcon on your class which returns the path.

function getIcon() {
return 'yourmodule/images/foo.png';
}

Avatar
socks

Community Member, 191 Posts

13 March 2011 at 9:45pm

I believe it's

function Icon() {
   return 'yourmodule/images/foo.png';
}

And thanks Graphicator, I've been wanting that US States dropdown in Userforms forever.

Avatar
Willr

Forum Moderator, 5523 Posts

15 March 2011 at 10:00pm

Avatar
dzon

Community Member, 1 Post

30 July 2016 at 1:30am

I created a class extending EditableMultipleOptionField. In the getFormField() provided the source for the field. This worked for me. Need to dev/build before use.