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.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Checkbox values


Go to End


3 Posts   1285 Views

Avatar
Arbee

Community Member, 31 Posts

28 June 2015 at 8:47am

Edited: 28/06/2015 11:42am

Hi, I have a simple checkbox which works fine but how do I write the values to the database rather than the IDs? This is simply for display purposes on a product page. At the moment it returns 1,2,3 or 4 but I want it to display Technique 1, Technique 2 etc. My code looks like this:

$field = new CheckboxSetField('Techniques', 'Select Techniques', array(
"1" => "Technique 1",
"2" => "Technique 2",
"3" => "Technique 3",
"4" => "Technique 4"));
$fields->addFieldsToTab(
"Root.Details",
array(
$field
)
);

btw each product may have more than one technique so radio buttons don't work here.
Thanks for your help.

Avatar
JonoM

Community Member, 130 Posts

29 June 2015 at 5:26am

The key is what gets stored, so you should just be able to make the key the same as the label:

array(
	"Technique 1" => "Technique 1",
	"Technique 2" => "Technique 2",
	"Technique 3" => "Technique 3",
	"Technique 4" => "Technique 4"
)

Avatar
Arbee

Community Member, 31 Posts

29 June 2015 at 6:15am

Thank you so much JonoM. That worked perfectly!