这是我的 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();
}}
这是我的 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">
**
上述功能正在工作,但在提交表单后,仍然检查验证码,一旦用户单击提交按钮,我想将其重置为未选中。
**
提前致谢