-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

1
  • did you execute $form->submit($request); or $form->handleRequest($request); ? Commented Sep 4, 2014 at 9:24

1 Answer 1

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/

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.