dropzone.jscloudconvert

Dropzone.js, how to refresh the page after action url is terminated


I use Dropzone.js to upload files to my server. I Create dropzones programmatically inside an existing form. My "url" parameter send the $_FILES array to my dropzone.php file who send the files submitted to cloudconvert to convert them to pdf file.

Dropzone refresh the initial page immediately after files are sent and do not wait for the running process in my dropzone.php ($process->wait();).

I can not find a way to force dropzone.js to wait until action is done.

ANy idea ?


Solution

  • As my dropzone form is inside another form, dropzone send the main form immediatly after file upload and do not wait for the dropzone verification process.

    To prevent this, I allow the main form to be validated only if I click the submit button.

    <script>
    $(document).ready(function() {
        Dropzone.autoDiscover = false;
    
        //Avoid form to be submitted by Dropzone
        var form_clicked = false;
        $('#submit_button').click(function() {
            form_clicked = true;
        });
        $("#submit_my_form").submit(function(e) {
            if(form_clicked != true){
               e.preventDefault();
            }
        });
        // Submit the main form to refresh page after file upload
        my_dropzone.on("successmultiple", function(file, responseText) {
            $('#submit_button').click();
        });
    </script>