tags:

views:

172

answers:

1

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  A: 

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.

deceze
not really understand how to perform that. what should i write for checked to true?? and i wanted to show all my compact data on checkbox. thanks for information, i need know more.. =)
vincent low
See updated answer. What do you mean by "show all compact data on checkbox"?
deceze
i mean, when my 'options' => $users, but the select checkbox din't show my $users information which i had $this->set(compact('user')); in my controller. the select list just show out few checkbox, but doesn't show any of the words, how can i show some value beside the checkbox, at least other know what is the checkbox for. thanks for ur update. i understand it much better. =)
vincent low
Sorry, see update.
deceze