Hi All,
In this blog we will discuss about how to set checkbox checked in cakePhp application.
You should set the checkbox checked/selected with the 'selected' option.
For example-
You can find a list of categories from the database table called Category as shown below:
$catLists= $this->Category->find('list', array(
'fields' => array('id')
));
$selectedCats= array(1,2,3);//this represents what all categories you want to be checked
Now you have to set all these values to the checkbox in cakephp's conventions
echo $this->Form->input('User.category', array(
'label' => 'Categories',
'type' => 'select',
'multiple' => 'checkbox',
'options' => $catlists,//you can set the variable as shown in above example in here
'selected' => $selectedCats//you can write in the list of the id's as defined in above example ,which will automatically display checkbox as selected with id's 1,2,3.
));
0 Comment(s)