ICode9

精准搜索请尝试: 精确搜索
首页 > 编程语言> 文章详细

php – 我可以使用Dropzone提交表单而无需上传任何文件吗?

2019-05-28 22:23:39  阅读:336  来源: 互联网

标签:jquery php forms dropzone-js


我遵循了Combine Dropzone With Normal Form教程,允许Dropzone上传和放大表格提交.表格是申请表格,应该与&没有添加文件.目前,仅当将一个或多个文件添加到Dropzone时,它才有效.

是否有一个选项我可以允许Dropzone处理表单提交,即使上传队列为空?

以下是我初始化表单的方法:

                Dropzone.options.general = {
                paramName: 'tx_ddapplicationform_applicationformgeneral[form][files]', // The name that will be used to transfer the file
                autoProcessQueue: false,
                uploadMultiple: true,
                parallelUploads: 100,
                maxFiles: 100,
                addRemoveLinks: true,
                previewsContainer: '.dropzone-previews', // we specify on which div id we must show the files
                clickable: false,


                // The setting up of the dropzone
                init: function() {
                    var myDropzone = this;
                    console.log(myDropzone)
                    console.log("Dropzone init");

                    console.log(this.element.querySelector("input[type=submit]"))

                    // First change the button to actually tell Dropzone to process the queue.
                   this.element.querySelector("input[type=submit]").addEventListener("click", function(e) {
                        // Make sure that the form isn't actually being sent.
                        console.log("the button is clicked")
                        e.preventDefault();
                        e.stopPropagation();
                        myDropzone.processQueue();
                        console.log("after processQueue")
                    });

                    // Listen to the sendingmultiple event. In this case, it's the sendingmultiple event instead
                    // of the sending event because uploadMultiple is set to true.
                   this.on("sendingmultiple", function() {
                        console.log("sending multiple");
                    });
                    this.on("successmultiple", function(files, response) {
                        console.log("success multiple");
                    });
                    this.on("errormultiple", function(files, response) {
                        console.log("error multiple");
                    });
                }

我浏览了dropzone.js表单并添加了console.logs来查看发生了什么.成功提交(添加了文件)记录下:

 processQueue dropzone.js:1301
 upload multiple dropzone.js:1314
 sending multiple main.jquery.js:551
 after processQueue main.jquery.js:545
 success multiple main.jquery.js:554

没有附加文件的不成功提交会记录下:

 processQueue dropzone.js:1301
 after processQueue main.jquery.js:545

解决方法:

好吧,可能是一个死灵帖子,但是因为我在谷歌结果页面的第一个链接中发现了这个问题,并且因为它被观看了很多,我认为答案不会伤害任何人.

我有相同的结构,并解决我刚才做的问题:

$('#my-dropzone input[type="submit"]').on('click', function(
    // Make sure that the form isn't actually being sent.
    e.preventDefault();
    e.stopPropagation();
    if (myDropzone.files.length) {
        myDropzone.processQueue(); // upload files and submit the form
    } else {
        $('#my-dropzone').submit(); // just submit the form
    }
});

请注意,如果您使用dropzone(第一种情况)提交表单,则通过ajax执行此操作,因此结果应由返回的响应处理,而如果您只提交表单(第二种情况),则您将获得正常的表单提交.

在我的情况下,这需要基于提交类型的不同响应.

标签:jquery,php,forms,dropzone-js
来源: https://codeday.me/bug/20190528/1174082.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有