Search code examples
phpjquerysymfonyinputjquery-file-upload

Input file field empty after uploading with jquery file upload


I'm trying to upload files and save the links in to my database with the jquery file upload plugin and the OneupUploaderBundle in Symfony.

I have an input file field in my form like this:

<input class="form-control" id="fileupload" type="file" name="files[]" data-url="{{ oneup_uploader_endpoint('gallery') }}" multiple />

In my jQuery I have this:

$('#form-Entity').submit(function (e) {
    e.preventDefault();
});

$('#fileupload').fileupload({
    dataType: 'json',
    add: function (e, data) {
        $("#submitentity").on('click', function () {
            data.submit();
        });
    },
    done: function (e, data) {
        console.log(data);
        $('#form-Entity')[0].submit();
    }
});

First I prevent the form from submitting. Then I upload the files. But when they are uploaded and I want to submit the form, the input files field is empty so I don't get anything in my backend ... . Also when I select images my input field still says 'no files selected'.

How can I fix this?


Solution

  • I created a list and every time a file is uploaded I add it to the list. At the end, before submitting the form I set the value of the hidden input field with the list.