我正在尝试找到一种使用 Google reCAPTCHA v3 验证 Semantic UI / Fomantic UI 表单的方法。我在 Stack 上找到了使用 Google reCAPTCHA v2 进行验证的选项。但是,新形式的 V3 验证有所不同,并使用另一种形式的用户界面。
更新:我找到了一种方法。我使用此来源作为初始参考:https://code.tutsplus.com/tutorials/example-of-how-to-add-google-recaptcha-v3-to-a-php-form--cms-33752 。使用 Semantic UI / Semantic UI 遵循验证形式。另一方面,要验证服务器上的数据,请按照前面的参考资料获取更多信息。
表格验证:
var formSelector = 'formSelector'; // Form selector
$('.ui.form')
.form({
onSuccess(event, fields){
var action = 'action'; // Action
var googleSiteKey = 'googleSiteKey'; // Google Site Key
grecaptcha.ready(function() {
grecaptcha.execute(googleSiteKey, {action: action}).then(function(token) {
$(formSelector).append('<input type="hidden" name="token" value="'+token+'">');
$(formSelector).append('<input type="hidden" name="action" value="'+action+'">');
$(formSelector).unbind('submit').submit();
});
});
return false;
}
});
Otavio,你可以发布你的表单验证代码吗?