21493 Posts in 5784 Topics by 2622 members
General Questions
SilverStripe Forums » General Questions » How to use a text field to create a select list (both in beckend)?
General questions about getting started with SilverStripe that don't fit in any of the categories above.
Moderators: martimiz, Howard, Sean, Ryan M., biapar, Willr, Ingo, swaiba, simon_w
|
Page:
1
|
Go to End | |
| Author | Topic: | 522 Views |
-
How to use a text field to create a select list (both in beckend)?

27 April 2011 at 1:10am
Hi,
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
-
Re: How to use a text field to create a select list (both in beckend)?

27 April 2011 at 8:58pm Last edited: 28 April 2011 1:43am
http://php.net/manual/de/function.explode.php
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(
'SelectModel'
);
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;
}
}
| 522 Views | ||
|
Page:
1
|
Go to Top |


