- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
是否可以合并 Google's incredible reCAPTCHA和 Matias Meno 令人难以置信的 dropzone.js ,以防止攻击和阻止垃圾邮件机器人?
最佳答案
使用WordPress。这是我根据一些教程得出的结论:
还有一些我不记得了
// Dropzone.autoDiscover = false; //I use Autodiscover
Dropzone.options.myAwesomeDropzone = { // The camelized version of the ID of the form element
// The configuration we've talked about above
autoProcessQueue: false,
uploadMultiple: true,
parallelUploads: 100,
maxFiles: 100,
previewsContainer: '.fileupload',
// The setting up of the dropzone
init: function() {
var myDropzone = this;
// 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.
e.preventDefault();
e.stopPropagation();
// myDropzone.processQueue();
var valid = true;
$('[data-required]').each(function(i,ele){
if(ele.value == ''){
$(this).parent().parent().addClass('alert');
valid = false;
}
});
if (!valid){
e.preventDefault();
scrollTop();
return false;
}
// Get the recaptcha input
var cap_input = grecaptcha.getResponse();
$.ajax({
url: homeUrl+'/wp-admin/admin-ajax.php',
type: "POST",
dataType: "JSON",
data: {
"action": "verifyReCaptcha",
"g-recaptcha-response": cap_input
},
success: function(response){
console.log(response);
if(response == 'Good captcha'){
if (myDropzone.getQueuedFiles().length > 0) {
myDropzone.processQueue();
}
else {
// Upload anyway without files
if (wantToUpload == 'unknown') {
$('#noFiles').modal();
e.preventDefault();
return false;
}
else if (wantToUpload == false) {
myDropzone.uploadFiles([ ]);
}
else {
myDropzone.uploadFiles([ ]);
}
}
}
else{
console.log('Spammer go away');
$('.g-recaptcha').addClass('alert');
}
}
});
});
// 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() {
// Gets triggered when the form is actually being sent.
// Hide the success button or the complete form.
console.log('sending');
});
this.on("successmultiple", function(files, response) {
// Gets triggered when the files have successfully been sent.
// Redirect user or notify of success.
console.log('success');
});
this.on("errormultiple", function(files, response) {
// Gets triggered when there was an error sending the files.
// Maybe show form again, and notify user of error
console.log('error');
});
}
}
还有一些 html/php
<form name="" action="<?=get_permalink();?>" method="post" id="my-awesome-dropzone" class="dropzone" enctype="multipart/form-data">
<label class="label" for="text-435">
<?=__('Name*','gt_domain');?>
</label>
<input type="text" name="client-name" value="" size="40" class="input__field--manami" id="text-435" data-required="true">
<!-- Lots of input fields -->
<div class="col-md-8 col-xs-12 fileupload dropzone-previews dz-message">
<h2 class="text-center" id="fileuploadtext">
<?=__('Click or drag and drop your file here <br>(Max 60mb)','gt_domain');?>
</h2>
</div>
<div class="g-recaptcha" data-sitekey="MY_PUBLIC_KEY"></div>
<input class="dangerzone-submit" type="submit" value="<?=__('Request quote','gt_domain');?>" name="dangerzone-submit">
</form>
在提交表单之前进行 ajax 验证:
function verifyReCaptcha(){
$email;
$comment;
$captcha = false;
if(isset($_POST['g-recaptcha-response'])){
$captcha=$_POST['g-recaptcha-response'];
}
if(!$captcha){
echo json_encode('Please check the the captcha form.');
exit;
}
$response=json_decode(file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=MY_SUPER_SECRET_GOOGLE_RECAPTCHA_KEY&response=".$captcha."&remoteip=".$_SERVER['REMOTE_ADDR']), true);
if($response['success'] == false){
echo json_encode('You are spammer ! Get the @$%K out');
}
else{
echo json_encode('Good captcha');
}
exit;
}
add_action( 'wp_ajax_nopriv_verifyReCaptcha', 'verifyReCaptcha' );
add_action( 'wp_ajax_verifyReCaptcha', 'verifyReCaptcha' );
最后接收表单输入和图像:
<?php
if (isset($_POST['dangerzone-submit'])) {
// print_r($_POST);
$client = $_POST['client-name'];
$email = $_POST['email'];
$company = $_POST['company'];
$phone = $_POST['phone'];
$comments = $_POST['comments'];
if ($_FILES) {
foreach ($_FILES as $file => $array) {
// print_r($array);
if ($_FILES[$file]['error'] !== UPLOAD_ERR_OK && $_FILES[$file]['error'][0] !== 0) {
echo "upload error : \n";
print_r($_FILES[$file]['error']);
print_r($_FILES);
die();
}
$uploads_dir = ABSPATH . 'wp-content/uploads/dropzone/';
$external_link = get_home_url().'/wp-content/uploads/dropzone/';
foreach ($array['name'] as $key => $val) {
print_r($key);
$name = $array['name'][$key];
$tmp_name = $array['tmp_name'][$key];
$newfilename = wp_unique_filename( $uploads_dir, $name );
$movefile = move_uploaded_file($tmp_name, $uploads_dir.$newfilename);
$uploaded_files[] = $external_link.$newfilename;
}
}
}
sendMail( //My func for sending mail
$client,
$email,
$company,
$phone,
$comments,
$uploaded_files
);
}
?>
关于reCAPTCHA 和 Dropzone JS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29589882/
我正在使用 dropzone js,它在我需要 dropzone 的页面上运行得很好。在任何其他页面上,它都会给我一个“无效的 dropzone 元素” 错误消息并导致我的其他 javascript
我已经设置了带有可点击元素的 dropzone。单击该按钮会导致 dropzone 打开文件选择器两次,而不是一次,第二次会在选择第一个文件后立即打开。 初始化代码是: Dropzone.autoDi
我正在尝试使用Dropzone.js重新创建放置的文件/文件夹的文件夹结构。 有没有办法访问每个文件的完整路径,以便可以在php端重新创建目录结构? 最佳答案 这是一种简单的方法,您可以另外发送某些文
我有一个 DropZone除了一个异常(exception),表单工作得很好,我似乎无法根据需要精确地限制文件类型。 使用 acceptedFiles: "image/*"暗淡所有不是图像的文件夹和文
我正在尝试使用 dropzone.js FAQ 以编程方式将现有图像添加到我的 dropzone作为指南: // Add the existing image if it's there. // he
我正在使用 dropzone 来处理文件上传,并且我正在使用预览容器来指定应显示上传文件的位置。 所以我的配置如下(只剩下相关部分): var myDropzone = new Dropzone("#
我想限制 Dropzone 在您单击指定的 dropzone 区域时只选择一个文件,但我找不到任何参数来执行此操作。现在,当我选择一个文件并点击打开时,Dropzone 会立即再次弹出打开文件对话框而
我想上传一个文件并根据文件大小设置宽度和高度以适应给定的 div。例如: div size: width: 600px, height: 300px img size: width: 1200px,
我正在使用 Dropzone.autoDiscover = false 并使用 element.dropzone() 创建我的放置区。我想在另一个容器中显示处理后的文件,所以我使用了 previews
我想在我的 Web 应用程序中创建一个拖放区,用于上传图像并使用 ImageMagick 操作它们。我的拖放区始终自动上传所有图像,并在拖放区中的图像预览上显示“对象对象”错误。服务器上的上传工作正常
我已经在我的 ASP.MVC 4 上成功实现了 dropzone.js。 但我需要缩短下拉区域的高度并翻译文本。 有什么简单的方法可以做到吗?我试图修改 CSS 没有结果;下拉区域仍然采用相同的高度。
在 dropzone (或vue2dropzone),有没有办法禁用文件上传并且仅**允许通过拖放添加到dropzone。 我有一个设置,我使用自定义预览模板成功地在拖放区中设置了拖放到子区域(可单击
是否可以使用外部按钮通过 Dropzone 插件添加文件?我找到了 documentation但它没有回答我的问题。确实,我无法使用诸如单击之类的处理程序事件添加文件。有解决办法吗? 最佳答案 我猜您
当我使用 dropzone 上传多个文件时,图标显示在框外。我这张图,下图中的dropzone表格是黄色的,但是当我选择很多文件时,它们会溢出并显示在表格之外。我的 dropzone 的 CSS 是
最新的 dropzone.js 版本似乎不适用于 IE11。如何测试? 1) 打开 https://www.dropzonejs.com/examples/simple.html在 IE11 2) d
我正在尝试使用Dropzone.js在我的 Laravel 网站上。 这是我的设置: index.blade.php: @csrf 在我的 app.js 文件中,我有以下代码: window.
我正在为我的网站使用 dropzone.js 并尝试在上传之前重命名文件。最近 dropzone 添加了新函数 renameFile,我无法开始工作。这是错误还是我对功能的理解有误? console.
我正在制作一个比较应用,它有两个不同的拖放区域。每个都应该像一个单独的拖放区(用于替换或删除每个图像)。 问题: var previewaDropzone = new Dropzone("div#pr
我觉得我在这里失去了理智。我已经阅读了与我的问题相关的所有线程,我添加了“Dropzone.autoDiscover = false;”但似乎没有任何效果。 我不断得到: Uncaught Error
我在我的应用程序上使用 react-dropzone,并希望在一个页面上有多个 dropzones 来预览多个图像。例如,我希望能够将英雄图像拖放到在页面顶部显示英雄图像的拖放区。然后,我想将不同的图
我是一名优秀的程序员,十分优秀!