Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add files from Dropzone to form

I want to use Dropzone.js so that the user can select images he wants to upload. But I do not want them to be uploaded on the fly, rather to just be added to form and then submitted the normal way in form array. How can I do that?

I've seen questions like How to get Dropzone.js to upload files only when a submit button is clicked?, but I do not need to upload them at all, I want Dropzone to add files to my form.

BTW, dropzone is in div, not on whole form, if it is important.

Is it possible?

like image 875
Paul Smalling Avatar asked Oct 20 '25 01:10

Paul Smalling


1 Answers

You need to set the autoQueue property to false when you initialize your dropzone instance:

var formData = new FormData();

//On addedfile:
Dropzone.options.myAwesomeDropzone = {
  autoQueue: false,
  init: function() {
    this.on("addedfile", function(file) { 
      formData.append("file", file); 
    });
  }
};

//On removedfile:
Dropzone.options.myAwesomeDropzone = {
  init: function() {
    this.on("removedfile", function(file) { 
      formData.delete('file');
    });
  }
};
like image 113
Faouzi Oudouh Avatar answered Oct 22 '25 14:10

Faouzi Oudouh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!