There is a model form.php :
public $date; public static function checkFormData() { $allNameEx = exercise::getAllExercises(); foreach($allNameEx as $item) { $nameEx[] = $item['name']; } return $nameEx; } The variable $nameEx returns:
Array ( [0] => Sport [1] => Reading [2] => Paint [3] => Walk ) In views / index, I create a form:
<?php $form = ActiveForm::begin(); ?> <?= $form->field($model, 'date')->widget(yii\jui\DatePicker::className(),['dateFormat' => 'yyyy-MM-dd'])?> <?= $form->field($model, 'name')->checkboxList(form::checkFormData()); ?> <div class="form-group"> <?= Html::submitButton('Отправить', ['class' => 'btn btn-primary']) ?> </div> <?php ActiveForm::end(); ?> I create a form with checkboxes and checkbox names:
<div id="form-name"> <label><input type="checkbox" name="form[name][]" value="0"> Sport</label> <label><input type="checkbox" name="form[name][]" value="1"> Reading</label> <label><input type="checkbox" name="form[name][]" value="2"> Paint</label> <label><input type="checkbox" name="form[name][]" value="3"> Walk</label> </div> In the label names from the array are pulled, but in the name="form[name][]" they do not fall, why?
And how do I get access to the check in the controller if the check box is checked or not?