contributte / forms-wizard

:tophat: Easy to use step-by-step form for Nette Framework
https://contributte.org/packages/contributte/forms-wizard.html
MIT License
15 stars 10 forks source link

Upload in wizard #4

Closed paveltizek closed 7 years ago

paveltizek commented 7 years ago

When form contains upload input in a step other than last, file is not sent. Variable $_FILES is empty.

MartkCz commented 7 years ago

You can save the uploaded file to temporary directory and save path or file name to session or move upload input to last step, other solution isn't.

For getting session: https://github.com/WebChemistry/wizard/blob/master/src/Wizard.php#L61

paveltizek commented 7 years ago

Thanks for reply, I can not move upload to last step. Now I am using your solution with temp directory but when I get back to upload step, it remove file. My code looks like this. Can you help me with it?

if (isset($this->values->image)) {
            $imagePath = $this->values->image;
            unset($this->values->image);
            if ($imagePath->name) {
                $wwwDir = $this->context->parameters['wwwDir'];
                $dir = '/images/object/' . 'temp';
                $filename = $imagePath->name;
                $filepath = "$dir/$filename";

                $imagePath->move($wwwDir . $filepath);
                //save to session

            }
        }

`

MartkCz commented 7 years ago

In your step with upload input

public function stepX() {
    $form->onSuccess[] = function ($form, $values) {
        if ($values->image->isOk()) {
            $path = ...; // save image
            $this->getSection()->image = $path;
        }
    };
}

and in finish method

$path = $this->getSection()->image;
paveltizek commented 7 years ago

Thanks for help. I solved this with similiar solution.