How to get Dropzone.js to upload files only when a submit button is clicked?

Posted on

How to get Dropzone.js to upload files only when a submit button is clicked? – Here in this article, we will share some of the most common and frequently asked about PHP problem in programming with detailed answers and code samples. There’s nothing quite so frustrating as being faced with PHP errors and being unable to figure out what is preventing your website from functioning as it should like javascript and php . If you have an existing PHP-based website or application that is experiencing performance issues, let’s get thinking about How to get Dropzone.js to upload files only when a submit button is clicked?.

for the past few days I’ve been trying to implement Dropzone into my form, but so far I had no luck figuring out how to make it upload and process the images only when the submit button gets clicked.
Therefore, I decided to come here and ask you guys for help.

I’ve made a example code structure so you can only take a look at what its necessary. Right now, I think its should work the way when I put some pictures into the Dropzone and click the button it triggers the collect_input function from the controller. But I have no clue how to process the files,etc. So, I guess what I’m asking for is a tip/solution on how to process the files from the form e.g.. Saving them to a folder and adding an entry to a database.

I’m gonna post the code below and if any of you have any tips or solutions please share them with me. I’d like to thank you all in advance for even reading this and for your replies. Btw I’m working in CodeIgniter.

[Download the whole project (css,js & php]


class Test extends CI_Controller {

    public function __construct() {



    public function index() {



    public function collect_input() {


<!DOCTYPE html>
        <meta charset="utf=8">
        <script src="" type="text/javascript"></script>                      

            <!--    Load DropZone        -->
            <link href="<?php echo base_url(); ?>/css/basic.css" type="text/css" rel="stylesheet" />
            <link href="<?php echo base_url(); ?>/css/dropzone.css" type="text/css" rel="stylesheet" />
            <script src="<?php echo base_url(); ?>js/dropzone.min.js"></script>
            <script type="text/javascript">
                    var myDropzone = new Dropzone("div#myId", { url: "file-upload"});
            <script type="text/javascript">
            Dropzone.options.myId = {

              // Prevents Dropzone from uploading dropped files immediately
              autoProcessQueue: false,

              init: function() {
                var submitButton = document.querySelector("#add")
                    myDropzone = this; // closure

                submitButton.addEventListener("click", function() {
                  myDropzone.processQueue(); // Tell Dropzone to process all queued files.

                // You might want to show the submit button only when 
                // files are dropped here:
                this.on("addedfile", function() {
                  // Show submit button here and/or inform user to click it.

            <?php echo form_open('test/collect_input'); ?>

                <!-- One of the many inputs of my form -->
                <select id="list_type">
                   <option value="-1">Chooose a type</option>

                   <option value="1">&gt;&gt;Type A</option>
                   <option value="2">&gt;&gt;Type B</option>

                <!--        Dropzone         -->
                <div id="myId" class="dropzone"></div>  

                <!-- Submit button-->
                <input type="submit" id="add" name="add" value="Add!!">

Solution :

You can supply your own url to upload the file. Currently I am just setting it as 'someurl'

Dropzone.autoDiscover = false;
jQuery(document).ready(function() {
  var myDropzone = new Dropzone("#myId", { 
    url: 'someurl',


$(document).ready(function () {
    Dropzone.options.dropzoneForm = {
        autoProcessQueue: false

function processEvent() { // call this to trigger the upload

<form action="/your-post-url-here" method="post" enctype="multipart/form-data" class="dropzone" id="dropzoneForm"></form>

Leave a Reply

Your email address will not be published. Required fields are marked *