0

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.

3
  • have u getting post value of "conditions" after submitting form in controller? Commented Sep 17, 2016 at 13:33
  • the value is always 0 in the db after submitting and in controller i don't have create none function for 'conditions' Commented Sep 17, 2016 at 14:00
  • @Saba Try putting your full view code,full controller code and full model code Commented Sep 17, 2016 at 21:11

1 Answer 1

1

You have to do like this :

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

I hope this will help!!.

Sign up to request clarification or add additional context in comments.

2 Comments

<?= $form->field($model, 'conditions')->checkbox(array('label'=>'Offerted')); ?> will do the same effect,this will post data as '0' when unchecked and '1' as checked.I think OP has got wrong in some other place
Work! Thank's so much.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.