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 /

[SOLVED]CheckboxSetField


Reply


3 Posts   534 Views

Avatar
phokki

Community Member, 14 Posts

16 April 2012 at 9:32pm

Hi SilverStripe guys,

I've an array:

protected $choices = array(
'Stafstaal',
'Balkstaal',
'Strippen',
'Platen',
'Speciaalstaal',
'Ronde buizen',
'Profielbuizen',
'Betonstaal',
'Bouwstaalmatten',
'Koudgewalste profielen'
);

this array has got 10 items,

So i want them as checkboxes so i use this code:

new CheckboxSetField(
'Producten',
'Wilt u meer weten over onderstaande productgroepen?',
$this->choices,
1
);

And then i use this code:

if ($key == 'Producten')
{
$selected_values = explode(',', $value);
$selected_products = array();
foreach ($selected_values as $value) {
$selected_products[] = $this->choices[$value];
}

$value = implode(', ', $selected_products);
}

So when i send this form to my email, i only see 9 items in my mail.
The first one is not in my mail (stafstaal).

And when i put /* and */ on the if statement, and send to my mail, i see an array 1,2,3,4,5,6,7,8,9. But normally
an array starts at 0 :P

Can anyone help me to get this work?
Should not be that hard but i cant figure it out...

Thanks!!!!

Avatar
phokki

Community Member, 14 Posts

16 April 2012 at 9:33pm

oh i forrgot something,

new CheckboxSetField(
'Producten',
'Wilt u meer weten over onderstaande productgroepen?',
$this->choices,
1 <----------------------------------------------
);

what is the 1 in the code above? i've no idea:D

Avatar
phokki

Community Member, 14 Posts

16 April 2012 at 10:35pm

kk got it working now,

protected $choices = array(
1 => 'Stafstaal',
2 => 'Balkstaal',
3 => 'Strippen',
4 => 'Platen',
5 => 'Speciaalstaal',
6 => 'Ronde buizen',
7 => 'Profielbuizen',
8 => 'Betonstaal',
9 => 'Bouwstaalmatten',
10 => 'Koudgewalste profielen'
);

this was the solution :D