using multiple radio button

6 0
13
Viewed: 79 679 times
Version: Unknown (update)
Category: Tips
Written by: francis ja francis ja
Updated by: Rohit Suthar Rohit Suthar
Created: Mar 7, 2012
Updated: 12 years ago

You are viewing revision #10 of this wiki article.
This is the latest version of this article.
You may want to see the changes made in this revision.

« previous (#9)

When we use multiple radio buttons with same name in Yii many people have the problem on getting the value of the selected radiobutton. The radioButtonList can be used for that, but if we need to use radioButton itself to place the button any where in a view, we need to include one more parameter in htmloption array().

'uncheckValue'=>null

Usage ΒΆ

echo CHtml::radioButton('btn', false, array(
    'value'=>'1',
    'name'=>'btnname',
    'uncheckValue'=>null
));

echo CHtml::radioButton('btn', false, array(
    'value'=>'2',
    'name'=>'btnname',
    'uncheckValue'=>null
)); 


//we can use it in activeRadioButton(), too
echo $form->radioButton($model, 'name', array(
    'value'=>1,
    'uncheckValue'=>null
));

echo $form->radioButton($model, 'name', array(
    'value'=>2,
    'uncheckValue'=>null
));

so we can place the radio button anywhere on the page.

regards

nintriva