checkbox problem

Hi, I have created a checkbox on each row of my CGridView list of items

now my problems are

  1. how to create an alert that pops when user clicks "add to favorites" when none of the checkboxes was checked at all

  2. how to pull datas from the checked boxes and save it ???

any help is appreciated. thanks in advance

here’s my code for the check box




<?php $this->widget('zii.widgets.grid.CGridView',array(

    'id' => 'wsrecruitcvhead-grid',

    'dataProvider' => $model->search(),

    #'filter' => $model,

    'columns' => array(

        array(

          'name' =>'',

          'value' => 'CHtml::checkBox("rid[]",null,array("value"=>$data->ResumeID,"id"=>"rid_".$data->ResumeID))',

          'type'=>'raw',

          'htmlOptions' => array('width'=>5),

          'visible' => !Yii::app()->user->isGuest,

        ),

        array(

           'name' => 'ResumeTitle',

           'value' =>$model->ResumeTitle,

        ),

        'ResumeSummaryIntroduction',

        'Name',

        array(

            'class' => 'CButtonColumn',

            'viewButtonUrl' => 'Yii::app()->createUrl("wsrecruitcvhead/view",array("id"=>$data["ResumeID"]))',

            'template'=>'{view}',

        ),

    ),

));

?>



You can use CCheckBoxColumn to generate your check box column.




  array(

    'class'=>'CCheckBoxColumn'

    'value' => '$data->ResumeID',

    'cssClassExpression'=>'"rid_".$data->ResumeID'

    'htmlOptions' => array('width'=>5),

    'visible' => !Yii::app()->user->isGuest,

  ),



To accomplish #1, use jquery to create an onclick event for the “Add to Favorites” link that cycles through the check boxes to see if any of them are checked. If they aren’t, trigger an alert.

I’m not sure about #2. Are you trying to save the values into a DB favorites table? If so, you’ll need to, in the same onclick event mentioned above, use jquery to gather all of the values for boxes that are checked and then post an AJAX request. Handle the request in the controller action by saving the data that was posted and returning whether or not the save was successful.

check this post out!

There is quite a good discussion about this problem with the possible solutions. ,

Or directly this #15, its exactly what u need!

u could solve ur problem with that.

yeah, I wanna save the values in favorites table, can you give me an example code snippet for that ?, I know nothing when it comes to ajax / jquery … ???

Check out Anupam’s link, post #15. There is code there that you can reference. Create an AJAX link and post it to an action where you can save the model data to the favorites table.

that #15th post has a different situation with mine ???

any other help ?