Get only selected checkbox

i have a form created by this code


	foreach ($options as $i=>$option)

	{

        echo CHtml::activeCheckBox($option,"[$i]optionid",array('checked'=>false,'value'=>$option->optionid)); 

	}

controller code is


...

        foreach($options as $i=>$option)

        {

           if(isset($_POST['Optionmodel'][$i]))

		{

            $option->attributes=$_POST['Optionmodel'][$i];

...

when in controller i check $option->attributes[‘optionid’] i see all checkboxes (selected and no-selected checkbox)

is this natural?

how to get only selected checkbox in controller or how to detect selected checkbox?

Active Checkbox API

If you don’t want the unselected ones to be submitted to the POST vars just pass


'uncheckValue' => null 

in the attributes array parameter.

Example:




        foreach ($options as $i=>$option)

        {

        echo CHtml::activeCheckBox($option,"[$i]optionid",array('checked'=>false,'value'=>$option->optionid,'uncheckValue' => null,)); 

        }



It passes a hidden 0 to the application otherwise so you can see all the checkboxes in your app even when not checked.

The other way is just to check that they have a value != 0.