S
S
Sergey2015-03-31 22:49:08
Yii
Sergey, 2015-03-31 22:49:08

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

2 answer(s)
A
Alzasr, 2015-04-01
@butteff

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

R
RR, 2015-03-31
@romkaby

Maybe a separate table and model for files?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question