A
A
Alexander2015-09-30 12:56:58
Yii
Alexander, 2015-09-30 12:56:58

How to properly work with checkbox in yii1?

Checkbox in file

<label>
   <?php echo $form->checkBox($model, 'home_office'); ?>
 выезд в офис / на дом
 </label>

html in browser
<label>
 <input id="ytUser_home_office" type="hidden" value="0" name="User[home_office]"><div id="User_home_office-styler" class="jq-checkbox" unselectable="on" style="-webkit-user-select: none; display: inline-block; position: relative; overflow: hidden;"><input name="User[home_office]" id="User_home_office" value="1" type="checkbox" style="position: absolute; z-index: -1; opacity: 0; margin: 0px; padding: 0px;"><div class="jq-checkbox__div"></div></div>                                        Возможен выезд в офис / на дом
                                    </label>

when checked
<?php
if(isset($_POST['User'])){
print_r($_POST['User']);
}
?>
Array ( [home_office] => 0
Values ​​are substituted from the first input - a, even if the input is not in the checked home_office state, everything will still equal zero.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Victor, 2015-09-30
@only-victor

www.yiiframework.com/doc/api/1.1/CHtml#activeCheck...
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'. Internally, a hidden field is rendered so that when the checkbox is not checked, we can still obtain the posted uncheck value. If 'uncheckValue' is set as NULL, the hidden field will not be rendered.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question