0

Im having some basic problems with that

    echo $this->Form->select('Already.alredyselected',$listnom,array(
        'multiple' => 'checkbox',
        'label' => 'Text Label',
        'selected' => $alreadyinvites,
        'class' => 'selbox'));

My arrays are:

   $alreadyinvites =  Array(
[258] => Banana Voadora
[196] => Jack Bob Rodrigo Silva Junior)

and:

     $listnom = Array(
[258] => Banana Voadora
[196] => Jack Bob Rodrigo Silva Junior
[259] => Toucinho Defumado

)

but the CakePHP 2.4 or 2.3.2 arent printing the Selected on checkbox, What im doing wrong ?

1
  • Pass the selected values down from the controller via request->data - That is the cleanes approach. selected/value keys will break your form on invalidation/post. Commented Jan 24, 2014 at 14:27

2 Answers 2

2

try

$alreadyinvites = array(258, 196);

and

echo $this->Form->select('Already.alredyselected',$listnom,array(
    'multiple' => 'checkbox',
    'label' => 'Text Label',
    'value' => $alreadyinvites,
    'class' => 'selbox'));
Sign up to request clarification or add additional context in comments.

3 Comments

Hash::extract($thiswavenominees, '{n}.Guest.id'); was returning values of ids as strings, not Int... i did a debug and found the problem. But thanks for the help !
I'm getting same issue in CakePHP 3.x, how to resolve same issue in CakePHP 3.0?
@yogeshsuhagiya maybe it's better if you post a new question describing your exact problem
0

Try this:

    $selected = array(2, 3);
    $options = array(1, 2, 3, 4);

echo $this->Form->input('Attendees', array('multiple' => true, 'options' => $options, 'selected' => $selected));

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.