I have created a checkBoxList() in a Form. I want to have the checkboxes checked, when the id of the tag in the database matches the values from the generated checkBoxList(). However, I was oblivious to the fact of how to compare the id from the server and the value (which is the ID) of the frontend.
This is what I have in the form.
<div class ="col-md-2">
<?php echo $form->labelEx($tag,'tag'); ?>
<?php echo $form->checkBoxList($tag, 'tag', CHtml::listData(Tag::model()->findAll(), 'idtag', 'tag'), array('id'=>'updateTag', 'name'=>'updateTag')); ?>
</div>
When using the code below, I can get the exact ID of the tags I need.
$criteria = new CDbCriteria();
$criteria->addCondition('t.fk_iddashboard ='."$model->iddashboard");
$dashboardHasTag = DashboardHasTag::model()->findAll($criteria);
foreach ($dashboardHasTag as $key => $value) {
$idTag = $value->fk_idtag;
}
Any advice on how to make it work?