-1

I have a question. It's possible to send an array in checkbox? For example I have the array :

public static $aColors = array(
    '1' => 'white',
    '2' => 'black',
    '3' => 'yellow',
    '4' => 'red',
    '5' => 'green',
    '6' => 'blue',
);

Now I want to send this array in a checkbox, I tried like this :

->add('colors', 'checkbox', array('mapped' => false, 'choices'   => Colors::aColors));

But I can't. Help me please. Thx in advance.

TanGio
  • 766
  • 2
  • 12
  • 34

1 Answers1

2

Try like this

 ->add('colors', 'choice', array('mapped' => false, 'choices'   => array(
                                              '1' => 'white',
                                              '2' => 'black',
                                              '3' => 'yellow',
                                              '4' => 'red',
                                              '5' => 'green',
                                              '6' => 'blue',
                                       ), 'expanded' => TRUE,
                                          'multiple' => TRUE
                                      ));

It will convert your choice into checkbox .

Ajeet Varma
  • 726
  • 4
  • 20