Upload files using the submit form button using Plupload

I am using the latest version of Plupload (2.1) - user interface widget

when i click upload files, it uploads all files correctly.

but when I try to upload files using the form submit button. he does not work. it just shows a small file upload and then submits the forms without completing the file upload.

here is my code:

jj = jQuery.noConflict();

jj(function() {

jj("#flash_uploader_other").plupload({
    runtimes : 'html5,flash,silverlight,html4',
    url : '/external/uploader-new/upload.php',
    max_file_size : '10mb',
    chunk_size : '1mb',
    unique_names : true,


    filters : [
    {title : "jpg,xls,csv,doc,pdf,docx,xlsx", extensions : "jpg,xls,csv,doc,pdf,docx,xlsx"}

    ],

    flash_swf_url : '/external/uploader-new/js/Moxie.swf',
    silverlight_xap_url : '/external/uploader-new/js/Moxie.xap'
});

// Handle the case when form was submitted before uploading has finished
jj('form').submit(function(e) {
    // Files in queue upload them first     

        if (jj('#flash_uploader_other').plupload('getFiles').length > 0) {
        // When all files are uploaded submit form
        jj('#flash_uploader_other').on('complete', function() {
            jj('form').submit();

        });
        jj('#flash_uploader_other').plupload('start');
    } 


});

Please, help!

thank

now works I replaced the following code

  jj('form').submit(function(e) {
// Files in queue upload them first     

    if (jj('#flash_uploader_other').plupload('getFiles').length > 0) {
    // When all files are uploaded submit form
    jj('#flash_uploader_other').on('complete', function() {
        jj('form').submit();

    });
    jj('#flash_uploader_other').plupload('start');
} 
  });

With this code:

jj('form').submit(function(e) {

            var uploader = jj('#flash_uploader_other').plupload('getUploader');
            // Validate number of uploaded files
            if (uploader.total.uploaded == 0)
            {
                // Files in queue upload them first
                if (uploader.files.length > 0)
                {
                    // When all files are uploaded submit form
                    uploader.bind('UploadProgress', function ()
                    {
                         jj('#flash_uploader_other').on('complete', function() {

                            jj('form').submit(); 

                             });
                    });

                   jj('#flash_uploader_other').plupload('start');
                } else { jj('form').submit();}
                    //alert('You must at least upload one file.');

                e.preventDefault();
            }


 });
+4
source share

Source: https://habr.com/ru/post/1534361/


All Articles