2017-08-14 32 views
0

这是我的PHP代码:如何在表单提交后重置recaptcha?

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(); 
}} 

这里是我的JavaScript代码:

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

这是我的验证码:

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

这是屁股在提交:

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

这也是我的表单ID:

<form id="i-recaptcha"> 

**

此上述功能正在工作,但提交表格后,仍然验证码 是选中后,我想将其重置为取消选中,一旦用户点击提交 按钮。

**

在此先感谢

回答

0

,你可以使用它像这样。它基于版本。

为版本1

Recaptcha.reload(); 

的版本2

grecaptcha.reset(); 
+0

我添加了这两种JavaScriptbut它不工作。我如何添加它? – James

+0

你使用哪个版本? – Bhautik

+0

我不知道哪个版本,你可以看到我的上面的代码。请给我一个解决方案。谢谢 – James