Jump to:

1970 Posts in 1272 Topics by 607 members

Form Questions

SilverStripe Forums » Form Questions » [SOLVED]CheckboxSetField

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

Page: 1
Go to End
Author Topic: 383 Views
  • phokki
    Avatar
    Community Member
    14 Posts

    [SOLVED]CheckboxSetField Link to this post

    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

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

    Thanks!!!!

  • phokki
    Avatar
    Community Member
    14 Posts

    Re: [SOLVED]CheckboxSetField Link to this post

    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

  • phokki
    Avatar
    Community Member
    14 Posts

    Re: [SOLVED]CheckboxSetField Link to this post

    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

    383 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.