Checkbox List Pre-Selected On Update

guys…

this is the code that i have in my view


<div class="row">

        <?php echo $form->labelEx($model, 'technology'); ?>

    <ul><?php echo CHtml::activeCheckboxList($model, 'technology',CHtml::listData(Technology::model()->findAll(), 'tech_id', 'tech_name'),array('template'=>'<li>{label}{input}</li>'));?>

        <div class="clearleft"></div>

    </ul>

        <?php echo $form->error($model, 'technology'); ?>

    

    </div>

while creating i have stored the data from checkboxes in the database using implode.

i want the check box list to be pre selected when i go to the update form.

how can i do it?

Hi, I don’t quite understand this part of your question:

Why would you use implode?! it’s true that you have multiple check boxes in your form but when the form is submitted only a single value will be returned and you should save 1 value in your db so there is no need for implode. If you do this then CHtml::activeCheckboxList() can select the right checkbox automatically.

Hi

did u added this in your rule method?

[color=#444444][font=Consolas, Menlo, Monaco,]array(‘technology’, ‘boolean’)[/font][/color]

Then its get saved… then it will automatically works as you expect :)

Thanks for your rep guyzzz

Have you tried this in your controller:


$model = $this->loadModel();


$model->technology = explode(", ", $model->technology);

follow this

[html]http://www.yiiframework.com/forum/index.php/topic/54518-checkboxlist-in-yii-framework-multiple-check-box-list-with-css/page__p__250478__fromsearch__1#entry250478[/html]

Thanks,

Srikanth