A
A
Alexander Sinitsyn2018-10-04 09:37:25
Yii
Alexander Sinitsyn, 2018-10-04 09:37:25

How to get an array from a form?

I add a field to the form like this

<?= $form->field($model, 'sort[' . $model->id . ']', ['options' => ['tag' => false], 'template' => '{input}'])->hiddenInput() ?>

Yii::$app->request->post() outputs like this
["sort"]=> array(5) { [14]=> string(1) "1" [13]=> string(1) "2 " [....
The validation rule in the model is
['sort', 'each', 'rule' => ['integer']],
Why does it get into the model after load like this?
["sort"]=> NULL
------------------
Question removed. I forgot to add 'sort' to the script... )))

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
eternalfire, 2018-10-04
@eternalfire

in the validation, a number is written, and here are strings

["sort"]=> array(5) { [14]=> string(1) "1" [13]=> string(1) "2" [....

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question