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.

Form Questions

Different field types in Create Page form


Reply

14 Posts   3952 Views

Avatar
Victor

17 March 2009 at 4:36am Community Member, 128 Posts

To work with Silverstripe, you need to be kiinda' comfortable with OO and MVC patterns ...

I will try to take a better look at the tutorials.... and OO and MVC. Thanks a lot for your patience

<?php
class Blabla extends Page {

public static $db = array(
'Companies' => 'Text'
);

function getCMSFields() {
$fields = parent::getCMSFields();
$fields->addFieldToTab('Root.Content.Companies', new OptionsetField('Companies', '', $DataObjectSet->toDropDownMap('id','name')));

return $fields;

}

}

class Blabla_Controller extends Page_Controller {

public function init() {
parent::init();
}
?>

flushing dies (no error but nothing after GhostPage)

Victor

Avatar
Fuzz10

17 March 2009 at 5:12am Community Member, 787 Posts

Yeah.. it isn't working code... Just a quick example to get the gist of it ...

But other than a Curly bracket and some other source data ... it should work ...

Avatar
Victor

17 March 2009 at 5:27am Community Member, 128 Posts

OK, I will try to make it work. Thanks: it points me in some direction

Avatar
Victor

18 March 2009 at 12:20am (Last edited: 18 March 2009 12:21am), Community Member, 128 Posts

OK, I almost got it

<?php
class TestPage extends Page {
static $db = array(
"Method" => 'Text'
);
function getCMSFields() {
$fields = parent::getCMSFields();
$fields->addFieldToTab("Root.Content.Main", new DropdownField("Method", "Select Method", array(
'First','Second'
)));
return $fields;
}
}

class TestPage_Controller extends Page_Controller {
}
?>

It stores, however, numerical values 0,1 instead of labels First, Second.

Avatar
Fuzz10

18 March 2009 at 12:30am (Last edited: 18 March 2009 12:31am), Community Member, 787 Posts

Yeah..

change :

array(
'First','Second'
);

into something like

array(
'Key'=>'value',
'Key'=>'value'
);

and it will store your key..

Avatar
Victor

18 March 2009 at 1:14am (Last edited: 18 March 2009 1:49am), Community Member, 128 Posts

Thanks! This works (on the contrary to recommended on the tutorial page to store PageColor). So finally working code (in case someone else needs it):

<?php
class TestPage extends Page {
static $db = array(
"Method" => 'Text'
);
function getCMSFields() {
$fields = parent::getCMSFields();
$fields->addFieldToTab("Root.Content.Main", new DropdownField("Method", "Select Method", array(
'First'=>'First Method',
'Second' =>'Second Method'
)));
return $fields;
}
}

class TestPage_Controller extends Page_Controller {
}
?>