Add a CAPTCHA

This commit is contained in:
smallxu038 2024-02-19 23:29:51 +08:00 committed by GitHub
parent 9a7a597ac1
commit 743bbd1a4c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -159,5 +159,33 @@
data-theme="orange"> data-theme="orange">
</div> </div>
<?php endif; ?> <?php endif; ?>
<?php if (akina_option('verification_type') == 'Google reCAPTCHA'&& akina_option('rehidden') == '1') {?>
<!--拦截表单提交并验证,验证后自动提交-->
<script>
$(document).pjax('a', '#pjax-container').on('pjax:end', function() {
// PJAX加载完成后重新加载Google验证码
$.getScript("https://www.recaptcha.net/recaptcha/api.js");
});
$('#commentform').on('submit', function(e) {
if (!$(this).data('form-submitted')) { // Check if the form was already submitted
e.preventDefault();
grecaptcha.ready(function() {
grecaptcha.execute();
});
}
});
function onRecaptchaSubmit(token) {
// Add the token to the form
var form = $('#commentform');
var input = $('<input>').attr('type', 'hidden').attr('name', 'g-recaptcha-response').val(token);
form.append(input);
// Now submit the form via AJAX
form.data('form-submitted', true); // Mark the form as submitted
form.trigger('submit'); // Trigger the form submit event
}
</script>
<?php }?>
</body> </body>
</html> </html>