Phim
(Pim Reijersen)
1
<?= $form->field($model, 'files')->fileInput(['multiple' => 'multiple']) ?>
Prints:
<input type="file" id="uploadform-files" name="UploadForm[files]" multiple="multiple">
However, the name should have a ‘[]’ suffix, like:
<input type="file" id="uploadform-files" name="UploadForm[files][]" multiple="multiple">
How can I accomplish this?
*edit
<?= $form->field($model, 'files')->fileInput(['multiple' => 'multiple', 'name' => 'UploadForm[files][]']) ?>
This works. Also passes $model->validate();. Feels hackerish, is it?
Can you show the Controller logic for the file upload. For me if the file upload is none then the validate fails.
Thnx
Dinesh
Phim
(Pim Reijersen)
3
public function actionUpload($id) {
$album = $this->findModel($id);
$model = new UploadForm;
if ($model->load(Yii::$app->request->post()) && $model->validate()) {
$files = UploadedFile::getInstances($model, 'files');
// TODO type filter
foreach($files as $file) {
if($file->type == 'image/jpeg') {
$this->savePhoto($album, $file);
}
}
return $this->redirect(['view', 'id' => $album->id]);
} else {
return $this->render('upload', [
'album' => $album,
'model' => $model
]);
}
}
I noticed that the UploadForm model has no rules, so that might be why mine validates and yours doesn’t 
Can’t test the rules right now.