如何将 DropzoneJS 图像字段设置为表单中的可选字段
How to make DropzoneJS image field as optional field in my form
我在表单中使用 dropzoneJS。除了图像,表单还记录用户输入。一切正常。用户输入将进入我的数据库,图像将上传到定义的目录中。
现在我想将拖放图像字段作为可选字段,用户可以选择上传图像或将其留空。但问题是,"submit" 按钮在用户放下图像之前不起作用。
所以请建议我如何制作提交按钮来提交表单,即使用户没有选择任何图像。我不是 javascript.
方面的专家
这是我的表单和按钮-
<form action="<?php echo $_SERVER["PHP_SELF"]; ?>" class="dropzone form-horizontal" id="my-awesome-dropzone" method="post" enctype="multipart/form-data">
<input type="text" ..blah blah
<input type .. blah blah
<!-- DropzoneJS div -->
<div class="dropzone-previews form-group" style="height: 350px;"></div>
<div class="fallback col-xs-3">
<input name="file" class="input-file form-control "type="file" multiple/>
</div>
<button type="submit" id="submit-dz" class="btn btn-primary" name="signup">Submit</button>
这是 javascript(设置必要的 dropzone 配置后,例如 autoProcessQueue: false and blah..blah)-
init: function() {
var myDropzone = this;
// Upload images when submit button is clicked.
$("#submit-dz").click(function (e) {
e.preventDefault();
e.stopPropagation();
myDropzone.processQueue();
});
}
您可以检查dropzone是否有文件要上传并相应地提交表单:
init: function() {
var myDropzone = this;
$("#submit-dz").click(function (e) {
e.preventDefault();
e.stopPropagation();
if (myDropzone.files.length) {
myDropzone.processQueue(); // upload files and submit the form
} else {
$('#my-awesome-dropzone').submit(); // submit the form
}
});
}
同时阅读 this 可能会对您有所帮助。
我在表单中使用 dropzoneJS。除了图像,表单还记录用户输入。一切正常。用户输入将进入我的数据库,图像将上传到定义的目录中。 现在我想将拖放图像字段作为可选字段,用户可以选择上传图像或将其留空。但问题是,"submit" 按钮在用户放下图像之前不起作用。 所以请建议我如何制作提交按钮来提交表单,即使用户没有选择任何图像。我不是 javascript.
方面的专家这是我的表单和按钮-
<form action="<?php echo $_SERVER["PHP_SELF"]; ?>" class="dropzone form-horizontal" id="my-awesome-dropzone" method="post" enctype="multipart/form-data">
<input type="text" ..blah blah
<input type .. blah blah
<!-- DropzoneJS div -->
<div class="dropzone-previews form-group" style="height: 350px;"></div>
<div class="fallback col-xs-3">
<input name="file" class="input-file form-control "type="file" multiple/>
</div>
<button type="submit" id="submit-dz" class="btn btn-primary" name="signup">Submit</button>
这是 javascript(设置必要的 dropzone 配置后,例如 autoProcessQueue: false and blah..blah)-
init: function() {
var myDropzone = this;
// Upload images when submit button is clicked.
$("#submit-dz").click(function (e) {
e.preventDefault();
e.stopPropagation();
myDropzone.processQueue();
});
}
您可以检查dropzone是否有文件要上传并相应地提交表单:
init: function() {
var myDropzone = this;
$("#submit-dz").click(function (e) {
e.preventDefault();
e.stopPropagation();
if (myDropzone.files.length) {
myDropzone.processQueue(); // upload files and submit the form
} else {
$('#my-awesome-dropzone').submit(); // submit the form
}
});
}
同时阅读 this 可能会对您有所帮助。