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've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Archive /

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

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

text as a key in CheckboxSetField


Go to End


4 Posts   2360 Views

Avatar
blaater

Community Member, 22 Posts

10 July 2007 at 4:43am

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

Forum Moderator, 628 Posts

10 July 2007 at 8:18am

Edited: 10/07/2007 8:19am

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

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

Example:


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

Avatar
blaater

Community Member, 22 Posts

10 July 2007 at 6:31pm

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

Avatar
Sigurd

Forum Moderator, 628 Posts

10 July 2007 at 6:38pm

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