1794 Posts in 590 Topics by 562 members
| Go to End | Next > | |
| Author | Topic: | 3232 Views |
-
Different field types in Create Page form

14 March 2009 at 3:53am
I am creating CustomPage.php
and I would like to have certain fields in CMS form to be of "Options" or "RadioButton" or ... type
Is it possible?Thank you in advance Victor
-
Re: Different field types in Create Page form

15 March 2009 at 11:19pm
Hi , welcome to Silverstripe !
Sure , no problem.
Have a look at :
http://doc.silverstripe.com/doku.php?id=form-field-types
and
http://doc.silverstripe.com/doku.php?id=data-types&s=field%20types -
Re: Different field types in Create Page form

16 March 2009 at 1:38pm Last edited: 16 March 2009 2:26pm
Thanks! But this documentation is a bit murky: Logically I would expect
Test.php:
<?php
class TestPage extends Page {
static $db = array(
'Foobar' => 'Optionset',
);static $has_one = array(
);function getCMSFields() {
$fields = parent::getCMSFields();
$fields->addFieldToTab('Root.Content.Main', new OptionsetField(
$name = "Foobar",
$title = "FooBar's optionset",
$source = array(
"1" => "Option 1",
"2" => "Option 2",
"3" => "Option 3",
"4" => "Option 4",
"5" => "Option 5"
),
$value = "1"
);, 'Content');return $fields;
}
}class TestPage_Controller extends Page_Controller {
}
?>return $fields;
}
}class TestPage_Controller extends Page_Controller {
}
?>
but flushing db results in an error.Victor
-
Re: Different field types in Create Page form

16 March 2009 at 9:31pm
You are confusing DB data field types : http://doc.silverstripe.com/doku.php?id=data-types&s=field%20types
with Form field types :
http://doc.silverstripe.com/doku.php?id=form-field-typesYou can use a Text field to store your values.
-
Re: Different field types in Create Page form

17 March 2009 at 1:41am
Yes, I looked again and it is clear (unless I am still confused) that
'Foobar'=>'Text'
However simple correction does not work: db flush still returns an error. I need to put somewhere description of the OptionsetField .
Unfortunately I cannot find a sample code (which would also work for checkboxes and radiobuttons) and would greatly appreciate the sample code.
Victor
-
Re: Different field types in Create Page form

17 March 2009 at 1:44am
Here is a quick example...
static $db = array(
'Companies' => 'Text',
);$fields->addFieldToTab('Root.Content.Companies', new OptionsetField('Companies', '', $DataObjectSet->toDropDownMap('id','name')));
Good luck !
-
Re: Different field types in Create Page form

17 March 2009 at 4:11am
Thanks, but I am still lost:
If I do simply like:
Test.php<?php
static $db = array(
'Companies' => 'Text',
);
$fields->addFieldToTab('Root.Content.Companies', new OptionsetField('Companies', '', $DataObjectSet->toDropDownMap('id','name')));
?>db flush does not generate a new page type even if I add
class TestPage_Controller extends Page_Controller {
}
but trying encapsulate the code in
<?php
class TestPage extends Page {
}
bring flush error
-
Re: Different field types in Create Page form

17 March 2009 at 4:17am
To work with Silverstripe, you need to be kiinda' comfortable with OO and MVC patterns ...
Also, please take a very good look at the tutorials....
Here is a more useful example....
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();
}
| 3232 Views | ||
| Go to Top | Next > |


