我想在不烦扰用户的情况下保护我的jquery按钮免受机器人攻击,所以我想添加google的隐形recaptcha.然而实现并不像我那么容易,我似乎无法做到这一点.如果有人能告诉我它是如何完成的那就太棒了.PS:我在wordpress主题上这样做.
这是文档:
https://developers.google.com/recaptcha/docs/invisible
创建隐形recaptcha:
https://www.google.com/recaptcha/admin#beta
这就是我所拥有的:
HTML:
<button class="acf-get-content-button">Show Link</button>
<div class="fa" id="acf-content-wrapper" data-id="<?php echo $post_id; ?>"></div>
Run Code Online (Sandbox Code Playgroud)
JS:
<script>
(function($) {
$('.acf-get-content-button').click(function(e) {
e.preventDefault();
$('.fa').addClass('fa-cog fa-spin fa-4x');
var $contentWrapper = $('#acf-content-wrapper');
var postId = $contentWrapper.data('id');
$.ajax({
url: "/public/ajax.php",
type: "POST",
data: {
'post_id': postId
},
})
.done(function(data) {
$('.fa').removeClass('fa-cog fa-spin fa-4x');
$contentWrapper.append(data);
$('.acf-get-content-button').removeClass().addClass('.acf-get-content-button')
});
});
$('.acf-get-content-button').mouseup(function() {
if (event.which == 1) {
$(".acf-get-content-button").hide();
}
});
})(jQuery);
</script>
Run Code Online (Sandbox Code Playgroud)
ajax.php
<?php
define('WP_USE_THEMES', false);
require_once( $_SERVER['DOCUMENT_ROOT'] . '/wp-load.php' );
global $post;
$post_id = …Run Code Online (Sandbox Code Playgroud) 我不明白 HTML 5。验证器说:
iframe 元素上的 marginwidth 属性已过时。请改用 CSS。
iframe 元素上的 marginheight 属性已过时。请改用 CSS。
但根据这个接受的答案:
无法在样式表中设置 iframe 的 marginheight、marginwidth 和 frameborder 属性。
为什么他们要求我做一些不可能的事情?
要么把有效的东西放在规范中,要么想出一个真正的替代方案。他们似乎已经弃用了某些东西,并且他们的替代方案不起作用。
我在这里缺少什么?