Search code examples
phpcheckboxyiiyii-chtml

How do I get the value from a checkbox in Yii?


I have a checkbox:

echo CHtml::checkBox("My checkbox", true, array());

How do I read its value through Yii? I know there's activeCheckBox which will link the value to a model attribute, but I don't want to create a new model class just to read a single value from a checkbox. Do I have to assign it an ID and get the value with javascript? Seems pretty absurd to me that Yii would have a function to create a checkbox but no way to retrieve its value afterwards… Also, since dynamic attributes don't work in Yii I can't just create an attribute on some other model that I have available.

How are the CHtml::checkBox elements in Yii intended to be used?


Solution

  • just use $_POST['My checkbox'] ;

    CHtml::checkBox just generate an input tag for you .

    you can open html source and see it .