I'm having some trouble with using Dropzone.js within a standard html form. With the code I have, everything is working as it should, I can click the area to add an image, I can only add one image at a time, and the image is only uploaded when the submit button is pressed. However, nothing is actually sent when submit is pressed. I know I need to manually process the queue, but this doesn't seem to be working at all. The rest of the form data is sent however, it's only the image which isn't.
我在标准html表单中使用Dropzone.js时遇到了一些麻烦。使用我的代码,一切正常,我可以单击该区域添加图像,我一次只能添加一个图像,并且只有在按下提交按钮时才会上传图像。但是,按下提交时实际上没有发送任何内容。我知道我需要手动处理队列,但这似乎根本不起作用。然而,其余的表单数据被发送,它只是不是的图像。
I'm using the following simplified code. (Assume that this works other than no file being sent.)
我正在使用以下简化代码。 (假设除了没有发送文件之外,这个工作正常。)
HTML
HTML
<form action='upload.php' method="post" class="dropzone" id="mydz">
<input type='submit' name='submitimage' value='Save' style='float:left;'/>
JAVASCRIPT
JAVASCRIPT
Dropzone.options.mydz = {
autoProcessQueue: false,
maxFiles: 1,
init: function() {
var submitButton = document.querySelector("#submitimage");
mydz = this; // closure
submitButton.addEventListener("click", function() {
mydz.processQueue(); // Tell Dropzone to process all queued files.
});
this.on('addedfile', function(file){ if(this.files.length > 1) { this.removeFile(this.files[0]); } });
}
}
I've been trying to solve this all day now, and no amount of searching online has revealed anything useful to me. Can any of you help?? :)
我一直在努力解决这个问题,现在网上搜索没有任何对我有用的东西。你们有人可以帮忙吗? :)
1 个解决方案
#1
-1
Bingo!!! With some help from the author of the github post i linked to earlier, this issue has now been resolved!
答对了!!!在我之前链接的github帖子的作者的帮助下,这个问题现在已经解决了!
The code I posted earlier works as it is, however inside the dropzone.js file, I added these two lines this.hiddenFileInput.setAttribute("name", _this.options.paramName); $("form.dropzone").append(_this.hiddenFileInput);
我之前发布的代码按原样运行,但是在dropzone.js文件中,我添加了这两行this.hiddenFileInput.setAttribute(“name”,_ this.options.paramName); $( “form.dropzone”)追加(_this.hiddenFileInput)。
after document.body.appendChild(_this.hiddenFileInput);
and all is working as it should!
在document.body.appendChild之后(_this.hiddenFileInput);一切都正常运作!
#1
-1
Bingo!!! With some help from the author of the github post i linked to earlier, this issue has now been resolved!
答对了!!!在我之前链接的github帖子的作者的帮助下,这个问题现在已经解决了!
The code I posted earlier works as it is, however inside the dropzone.js file, I added these two lines this.hiddenFileInput.setAttribute("name", _this.options.paramName); $("form.dropzone").append(_this.hiddenFileInput);
我之前发布的代码按原样运行,但是在dropzone.js文件中,我添加了这两行this.hiddenFileInput.setAttribute(“name”,_ this.options.paramName); $( “form.dropzone”)追加(_this.hiddenFileInput)。
after document.body.appendChild(_this.hiddenFileInput);
and all is working as it should!
在document.body.appendChild之后(_this.hiddenFileInput);一切都正常运作!