WebChemistry / images

Image storage for Nette Framework
36 stars 20 forks source link

When using multiple uploadcontrols in form, only last one is processed #17

Closed JanMikes closed 6 years ago

JanMikes commented 8 years ago

Hello, i need to use multiple uploadcontrols in one form (not possible to use multiupload, i need to differ images), but only last one is processed.

Following code:

$form->addImageUpload("test1", "test1")
    ->setRequired();

$form->addImageUpload("test2", "test2")
    ->setRequired();

$form->addImageUpload("test3", "test3")
    ->setRequired();

See result of xdebug breakpoint in process function (without modifing values), tried same image 3 times. I tested even with 2 or more images, same result, always only last one is uploaded with imagestorage.

Tried both stable and @dev version, same result.

JanMikes commented 8 years ago

As workaround i use in process method this:

$this->fixNonUploadedImage($values->test1, "test1");
$this->fixNonUploadedImage($values->test2, "test2");
private function fixNonUploadedImage(& $value, $namespace)
{
    if ($value instanceof FileUpload) {
        $value = $this->imageStorage->saveUpload($value, $namespace);
    }
}