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're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

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

How to use a text field to create a select list (both in beckend)?

Go to End

2 Posts   1080 Views


Community Member, 107 Posts

27 April 2011 at 1:10am


I want to create a select list with data taken from a text field. The text field is listed in the backend and so is the select list.

The text field should be something like "Value 1,Value XY, Another Value" (separated by comma) and is located at the page holder. The pages underneath this holder should show the select list with the values taken from the before mentioned text field.

With what I don't have problems is creating the single elements. My problem ist to parse the text field values to the select list.

Any help appreciated!

Cheers, Mario


Community Member, 344 Posts

27 April 2011 at 8:58pm

Edited: 28/04/2011 1:43am

You should also consider using a simple DataObject for this, so if anyone deletes values in the TextField your keys won't get mixed up.

Something like:

class SelectModelAdmin extends ModelAdmin {
	public static $managed_models = array(
	static $url_segment = 'selectadmin';
	static $menu_title = 'Select Admin';
class SelectModel extends DataObject {
	static $db = array('Name' => 'Text');
	static $searchable_fields = array('Name');
class Page extends SiteTree {
	static $has_one = array(
		'Select' => 'SelectModel',
	function getCMSFields() {
		$fields = parent::getCMSFields();
		$select = new DropdownField('SelectID', 'Select', DataObject::get('SelectModel')->map('ID','Name'));
		$fields->addFieldToTab('Root.Content.Main', $select, 'Content');
		return $fields;