Saving a checkbox value in Yii

You can use htmlOptions array to specify value attribute. Below is the code example:

<?php echo $form->labelEx($model,'active'); ?>
<?php echo $form->checkBox($model,'active', array('value'=>1, 'uncheckValue'=>0)); ?>
<?php echo $form->error($model,'active'); ?>

Since version 1.0.2, a special option named 'uncheckValue' is available that can be used to specify the value returned when the checkbox is not checked. By default, this value is '0'. (This text is taken from YII Documenration)


For every input that you are accepting from user, you need to define it in model::rule(). is active defined there in rule()?

Tags:

Yii