-1

I'm having trouble uploading a file, when I dump the data returned by $form->getData(), the file field is always null. Also, if I do $this->getRequest()->files->all() I get an empty array().

This is the field definition in my form type:

->add('card_file', 'file', array(
                                'label' => 'Examinar',
                                'required' => false,
                                )
)

And this is how I print the field in the .twig file:

<fieldset class="fieldset__upload">

    {{ form_widget(addressForm.card_file) }}

</fieldset>

The tag is created with enctype="multipart/form-data", also, the form isValid() and the file is about 4kb in size, so I don't think is a problem of exceeding file size.

The form is not attached to an entity, and $form->getData() returns all other fields correctly.

Any ideas? Thank you in advance

Joel
  • 51
  • 9

1 Answers1

0

I think I found the problem, it didn't had anything to do with Symfony2.

This form is submitted via AJAX, and I didn't know until now that serialize() doesn't send file data.

That was the problem altogether, I will update the answer with the correct JavaScript code as soon as I can get it to work.

EDIT:

I used the jQuery Form plugin for AJAX for uploading the file:

http://www.malsup.com/jquery/form/

Joel
  • 51
  • 9