mirror of
https://github.com/mashirozx/sakura.git
synced 2024-12-12 09:54:35 +08:00
Add a CAPTCHA
This commit is contained in:
parent
9a7a597ac1
commit
743bbd1a4c
28
footer.php
28
footer.php
@ -159,5 +159,33 @@
|
||||
data-theme="orange">
|
||||
</div>
|
||||
<?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>
|
||||
</html>
|
||||
|
Loading…
Reference in New Issue
Block a user