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.

Archive

Our old forums are still available as a read-only archive.

Moderators: martimiz, Sean, biapar, Willr, Ingo, simon_w

text as a key in CheckboxSetField


Reply

4 Posts   1824 Views

Avatar
blaater

10 July 2007 at 4:43am Community Member, 22 Posts

Hello,

I'm a newbie to the silverstripe cms, but must say: What a great framework is this!!

I'm trying to add a checkboxgroup in the cms with some text as the keys, but I only get id's as the value.

In the documentation is told that you can have text as a key instead of an id in a checkboxgroup:
http://doc.silverstripe.com/doku.php?id=checkboxsetfield&s=checkboxsetfield

I've tried it with:
$fields->addFieldToTab('Root.Content.Main',new CheckboxSetField('Opleiding','Opleiding',array('VMBO','HAVO','VWO','MBO','HBO','WO'),array('VMBO','HAVO','VWO','MBO','HBO','WO')));

but still there are id's as keys.

Can somebody help me out?

Thanks.

Avatar
Sigurd

10 July 2007 at 8:18am (Last edited: 10 July 2007 8:19am), Forum Moderator, 628 Posts

You need to pass keys as array keys. This is explained in Tutorial 3 that Andy made :)

[url]http://doc.silverstripe.com/doku.php?id=tutorial:3-forms[/url]

Example:

$browsers = array(
'FF' => 'Firefox',
'IE' => 'Internet Explorer',
'Safari' => 'Safari',
'Opera' => 'Opera',
'Lynx' => 'Lynx'
);
$browserField = new OptionsetField('Browser', 'Your Favourite Browser', $browsers)

Avatar
blaater

10 July 2007 at 6:31pm Community Member, 22 Posts

Thanks for your reply,
Stupid of me not to try it like this :)

Avatar
Sigurd

10 July 2007 at 6:38pm Forum Moderator, 628 Posts

Sweet. Note the dropdown/optionset/checkbox are basically all the same thing in terms of passing data to them.