mercredi 25 novembre 2015

Get file from form that is dynamically added

On my website, I have an slider with images. In the backend, the current slider images are displayed as well as a button that adds an input field, so I can upload new images for the slider.

The code to add the input field is done with some jQuery. When I click the button, the following Javascript function is being executed:

function addSliderImageEdit(){
    dataToAppend =
        "<li class='list-group-item'>" +
        "<div class='form-inline'>" +
        "<div class='input-group'>" +
            "<input type='file' id='slider-edit' class='slider-edit' name='slider-edit'/>"+
        "<span class='input-group-btn'>" +
        "<button class='btn btn-danger btn-remove-image-upload' type='button'>Verwijder afbeelding</button>" +
        "</span>" +
        "</div>" +
        "</div>" +
        "</li>";

    $('#btn-add-image-upload').on('click', function () {
        $(".list-group")
            .append(dataToAppend);
    });

    $('.list-group').on('click', '.btn-remove-image-upload', function () {
        $(this).parent().parent().parent().parent().remove();
    })
}

The code works well and an input field with a remove button is being added.

The problem is that I can't access images that are uploaded with this dynamically added input field. When I use Input::file() or Request::file('slider-edit'), the result is always null.

I think it's because I don't use the Laravel Form Builder to create these dynamic input fields. I tried to change the Javascript code so that it uses the Laravel Form Builder, but it wouldn't work.

So, does someone know how I can access these files that are being uploaded with the dynamically added input field in Laravel?

Thanks in advance.



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/1OrQnCM
via IFTTT

Aucun commentaire:

Enregistrer un commentaire