1

My DB column name subscribed tinyint(1),

I want if checkBox is checked then value send 1 if not checked then value send 0.

This is my code-

<?php echo $form->checkBox($model,'subscribed'); ?>

Please help.

2 Answers 2

3

Try this:

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

Here, value for checked checkbox is 1 and unchecked checkbox is 0

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

Comments

2

In your view file:

<?php echo $form->checkBox($model,'attribute'); ?> //in your case 'attribute' is 'subscribed'

in your controller

<?php
//if checked, return 1;
//if unchecked, return 0;
.........
$checkbox_value=$model->attribute; //in your case 'attribute' is 'subscribed'
echo $checkbox_value;
.......
?>

Comments

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.