webmozart / standalone-forms

139 stars 30 forks source link

Not working for file uploads #1

Closed Lc5 closed 11 years ago

Lc5 commented 11 years ago

Hello, I've got file upload field in my form. The data is correctly sent using POST, however, when using the following code, the UploadedFile object is not created, when calling "$form['attachment']->getData():"

$builder->add('attachment', 'file');

if ($form->isValid()) { $someNewFilename = ...

    $form['attachment']->getData()->move($dir, $someNewFilename);

    // ...
}

Calling $form->getData() returns, among others, an array of fields with user file names. I suppose the problem could be in FileBag not being called at all.

webmozart commented 11 years ago

For automatic handling of file uploads, you need to also install symfony/http-foundation and enable HttpFoundationExtension.

use Symfony\Component\Form\Extension\HttpFoundation\HttpFoundationExtension;

$formFactory = Forms::createFormFactoryBuilder()
    ->addExtension(new CsrfExtension($csrfProvider))
    ->addExtension(new ValidatorExtension($validator))
    ->addExtension(new HttpFoundationExtension())
    ->getFormFactory();
Lc5 commented 11 years ago

Thanks for explanation!