Search code examples
yii2yii2-model

yii2 checkbox field dont'save data in db


i have a problem with the checkbox field that does not save me the data in the database . In the database I have the ' conditions ' field ( chekbox field ) as boolean . when sending the form I do not save as checked ( 1 ) .

my model Rules

return[
 'condizioniRequired' => ['conditions','required'],
            'condizioniType' => ['conditions','boolean'],];

My view

<?= $form->field($model, 'conditions')->checkbox(array('label'=>'Offerted')); ?>

all other fields are saved.


Solution

  • You have to do like this :

    <?= $form->field($model, 'conditions')->checkBox(['uncheck' => '0', 'checked' => '1'])->label('label'=>'Offerted') ?>
    

    I hope this will help!!.