kentuck1213
@kentuck1213

Как правильно работать с checkbox в yii1?

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

html в браузере
<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>

при чекеде
<?php
if(isset($_POST['User'])){
print_r($_POST['User']);
}
?>
Array ( [home_office] => 0
Значения подставляется из первого input - a, даже если input не в состояние чекед home_office все ровно будет равнять нулю.
  • Вопрос задан
  • 1138 просмотров
Пригласить эксперта
Ответы на вопрос 1
only-victor
@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.
Ответ написан
Комментировать
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы