Answer the question
In order to leave comments, you need to log in
Why does the name not get into name?
There is a model form.php
public $date;
And
public static function checkFormData()
{
$allNameEx = exercise::getAllExercises();
foreach($allNameEx as $item)
{
$nameEx[] = $item['name'];
}
return $nameEx;
}
Array
(
[0] => Sport
[1] => Reading
[2] => Paint
[3] => Walk
)
<?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(); ?>
<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>
Answer the question
In order to leave comments, you need to log in
And they shouldn't go there. The keys of the array fall into the value of the input. This is quite enough. You can change
to
but I would do this:
public static function checkFormData()
{
$allNameEx = exercise::getAllExercises();
return ArrayHelper::map($allNameEx, 'name', 'name');
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question