mardi 5 février 2019

how to submit dropzone.js with different buttons

I am using dropzone.js with Laravel. I am submitting dropzone files with two different buttons see in the below image. when I click on Merge and upload as one file then want to send this button value to the controller. when I click on Save each file separately then I want to send this button value controller. I have tried like this, I have to take a global variable which is input it working fine but the problem is that when I hit a button every time it sends old value not current value. Thanks for your help.

enter image description here

Here is my form.

<form action="" class="dropzone dropzone-nk needsclick" id="my-awesome-dropzone" method="post" enctype="multipart/form-data">
                            
                                <div class="dz-message needsclick download-custom">
                                    <i class="notika-icon notika-cloud"></i>
                                    <div class="fallback"> 
                                        <input name="file" type="file" multiple />
                                    </div>
                                    <h2>Drop files here or click to upload.</h2>
                                </div>
                            </div>
                            <br>
                            <div class="text-center">
                                <input type="button" class="btn-success submit-merge" id="merge_file" value="Merge and Upload as one file" style="padding:0.8em">

                                <input type="button" class="btn-success submit-separate" id="separate_file" value="Save each file separatly" style="padding:0.8em">
                            </div>
                        </form>

Here Is Script for the dropzone.

<script>

Dropzone.options.myAwesomeDropzone = { // The camelized version of the ID of the form element

    // The configuration we've talked about above
    autoProcessQueue: false,
    uploadMultiple: true,
    parallelUploads: 25,
    maxFiles: 25,
    acceptedFiles:'.pdf',

    // The setting up of the dropzone
    init: function() {
        var myDropzone = this;
        var input = 'Null';


        $(".submit-merge").click(function (e) 
        {
            alert('
                    <input >
            ');
            e.preventDefault();
            e.stopPropagation();
            myDropzone.processQueue();

            input = 'merge_file';

            console.log(input);
        });



        $(".submit-separate").click(function (e) {
            e.preventDefault();
            e.stopPropagation();
            myDropzone.processQueue();

            input = 'separate_file';
            console.log(input);
        }); 
        // });

        // $(".submit-separate").click(function (e) {
        this.on("sendingmultiple", function(file, xhr, formData) {
        //Add additional data to the upload
            formData.append(input, $('#'+input).val());
        });

        this.on("success", function(file, responseText) {
            // location.reload();
            console.log('dfd');
        });

    }
}

</script>



from Newest questions tagged laravel-5 - Stack Overflow http://bit.ly/2G97Vsp
via IFTTT

Aucun commentaire:

Enregistrer un commentaire