Saba
Saba

Reputation: 115

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.

Upvotes: 0

Views: 1366

Answers (1)

Rahul Pawar
Rahul Pawar

Reputation: 1036

You have to do like this :

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

I hope this will help!!.

Upvotes: 1

Related Questions