Contact Form 7 删除上传的文件
Contact Form 7 remove uploaded file
请问是否可以添加到 WordPress 中的联系表 7 按钮以删除上传的文件?
add button for removing file
非常感谢。
亲切的问候,
一月
如果我理解你的问题是正确的,你希望能够在提交表单之前 cancel/reset 在 <input type="file" />
字段中选择文件。如果这是你想要的,简短的回答是否定的,没有任何 cf7 标签可以做到这一点,也没有任何插件扩展可以做到这一点(我还知道:)。您将需要使用一些自定义 javascript.
在您的表单中自己实现它
要将自定义 javascript 上传到联系表 7,您可以参考此 answer。
要重置文件输入字段,可以参考这个answer。
希望对您有所帮助。
We can easily achieve with simple jquery click function.
这是我们的文件上传html,所以我们可以写一个点击功能
<input type="file" name="file-711" size="40" class="wpcf7-form-control wpcf7-file" id="imgupload" accept=".png,.jpg,.jpeg,.pdf,.doc,.docx" aria-invalid="false">
Jquery
$(document).ready(function () {
$('#imgupload').change( function(event) {
var len = $('.img-remove').length;
if(len < 1){
$('.fileupload-wrp').append('<a class="img-remove" id="remvImg" style="" onclick="removeimg()" data-toggle="tooltip" data-placement="bottom" title="" data-original-title="Remove Image"><i class="fa fa-trash"></i></a>');
}
});
}); //imgupload is the file upload id
对于每次上传,我都会附加删除按钮
Remove click event
function removeimg(){
if(confirm("Are you sure you want to delete this?")){
$('#imgupload').val('');
$("#remvImg").remove();
}
}
请问是否可以添加到 WordPress 中的联系表 7 按钮以删除上传的文件?
add button for removing file
非常感谢。
亲切的问候,
一月
如果我理解你的问题是正确的,你希望能够在提交表单之前 cancel/reset 在 <input type="file" />
字段中选择文件。如果这是你想要的,简短的回答是否定的,没有任何 cf7 标签可以做到这一点,也没有任何插件扩展可以做到这一点(我还知道:)。您将需要使用一些自定义 javascript.
要将自定义 javascript 上传到联系表 7,您可以参考此 answer。
要重置文件输入字段,可以参考这个answer。
希望对您有所帮助。
We can easily achieve with simple jquery click function.
这是我们的文件上传html,所以我们可以写一个点击功能
<input type="file" name="file-711" size="40" class="wpcf7-form-control wpcf7-file" id="imgupload" accept=".png,.jpg,.jpeg,.pdf,.doc,.docx" aria-invalid="false">
Jquery
$(document).ready(function () {
$('#imgupload').change( function(event) {
var len = $('.img-remove').length;
if(len < 1){
$('.fileupload-wrp').append('<a class="img-remove" id="remvImg" style="" onclick="removeimg()" data-toggle="tooltip" data-placement="bottom" title="" data-original-title="Remove Image"><i class="fa fa-trash"></i></a>');
}
});
}); //imgupload is the file upload id
对于每次上传,我都会附加删除按钮
Remove click event
function removeimg(){
if(confirm("Are you sure you want to delete this?")){
$('#imgupload').val('');
$("#remvImg").remove();
}
}