Answer the question
In order to leave comments, you need to log in
How to add multiple identical model form fields in yii2?
The bottom line is that you need to give the user the opportunity to upload several files to the form, as much as he wants. Well, i.e. functionality with file input + javascript layer, which will allow you to add more inputs, as many as the user wants. The question is how to tie it on yii2 competently? How to register an infinite file input?
Fields that I can create, as a field of the same property. But after validation on the backend, one property will contain the last file, no more. How to tie all this? Or will you still have to limit the number of files?
Answer the question
In order to leave comments, you need to log in
Name for input type=file make it an array, i.e. something like <input type=file name="images[]" />
then $_FILES['images'] will be an array. I wrote you the essence, do not use $_FILES directly. When rendering an input in Yii2, set the name yourself in the form of an array $form->field($model,'upload[]')->fileInput(), and in the model (or form) treat the upload attribute as an array
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question