简体   繁体   English

如何重置 Google reCaptcha?

[英]How to reset Google reCaptcha?

Here is my PHP Code:这是我的 PHP 代码:

    function post_captcha($user_response) {
    $fields_string = '';
    $fields = array(
        'secret' => '',
        'response' => $user_response
    );
    foreach($fields as $key=>$value)
    $fields_string .= $key . '=' . $value . '&';
    $fields_string = rtrim($fields_string, '&');
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, 'https://www.google.com/recaptcha/api/siteverify');
    curl_setopt($ch, CURLOPT_POST, count($fields));
    curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, True);
    $result = curl_exec($ch);
    curl_close($ch);
    return json_decode($result, true);
}
$res = post_captcha($_POST['g-recaptcha-response']);
if (!$res['success']) {
      die('MF005');
} else {
if ($mail->send()) { 
$send_arEmail = $autoresponder->Send();
}}

and here is my JavaScript code:这是我的 JavaScript 代码:

<script src="https://www.google.com/recaptcha/api.js" async defer></script>
<script>
function onSubmit(token) {
    document.getElementById("i-recaptcha").submit();
}
</script>

This is my captcha:这是我的验证码:

<div class="g-recaptcha" data-sitekey="" ></div>

and this is button submit:这是按钮提交:

<button class="button rounded" type="submit" data-callback="onSubmit">Send</button>

This is also my form id:这也是我的表单 ID:

<form id="i-recaptcha">

** **

This above function is working, but after submit form, still captcha is checked, I want to reset it to unchecked once user click on submit button.上述功能正在运行,但在提交表单后,仍然选中验证码,一旦用户单击提交按钮,我想将其重置为未选中状态。

** **

Thanks in advance提前致谢

You can use it like this.你可以像这样使用它。 It's based on version.它基于版本。

Version 3版本 3

grecaptcha.ready(function() {
    grecaptcha.execute('SITE_KEY', {action: 'homepage'}).then(function(token){
        $('#token').val(token);
    });
});

Version 2版本 2

grecaptcha.reset();

Version 1版本 1

Recaptcha.reload();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM