0
votes

i plan to set a checkbox with selected option in my form. but i am unable to show my checkbox content in the form, i cant see any value instead of just a box for me to select.

how to show value while i using checkbox? i able to show my value while i using select. this is in a HABTM model. any hints?

here is my selection code.

input('User',array('label' => 'Select Related Potential', 'multiple'=>'checkbox', //'options' => $users, 'legend'=>$users, //'value'=>$users, //'id'=>$ownUserId, 'default'=>$ownUserId, 'style'=>'width:200px;height:100px', 'selected' => $ownUserId, )); ?>
1

1 Answers

1
votes

This may be relevant:

You cannot use default to check a checkbox - instead you might set the value in $this->data in your controller, $form->data in your view, or set the input option checked to true.


For example:

// in Controller
$this->data['Model']['field'] = true;

Causes the field to have the value true, which will result in a checked checkbox for this field.

Or:

$form->input('Model.field', array('checked' => true));

Always checks the checkbox.

Or:

$form->input('Model.field', array(
    'checked' => ($this->data['Model']['field'] == 'xxx')
));

Dynamically sets the checkbox based on whether $this->data['Model']['field'] is 'xxx' or not.


Sorry, completely misunderstood the question.

Did you find your users via list? The options array needs to be in a particular format, a normal find() won't do that.