可以在没有google recaptcha v2验证的情况下提交联系表单

问题描述 投票:0回答:1

我在php中使用了一个联系表单并在其上添加了google recaptcha。但是我可以在没有重新验证的情况下提交表单。如何根据需要进行重新回收。我已经尝试了一些解决方案,但它们都没有为我工作。感谢你的回答。谢谢

<form name="contact" method="post" action="" id="fsrep-contact-form">
  <table cellspacing="0" cellpadding="1" border="0">
    <tr id="fname">
      <td>First Name <span>*</span></td>
      <td><input type="text" name="fname" required></td>
    </tr>
    <tr id="lname">
      <td>Last Name</td>
      <td><input type="text" name="lname"></td>
    </tr>
    <tr id="emailid">
      <td>Email <span>*</span></td>
      <td><input type="email" name="email" id="mail" required></td>
    </tr>
    <tr id="phone-no">
      <td>Cell Phone <span>*</span></td>
      <td><input type="number" name="phone" required></td>
    </tr>
    <tr>
      <td>Please give us any other details you would like, that would help us to help you find your next home</td>
      <td><textarea name="message"></textarea></td>
    </tr>
    <tr>
      <td>
        <div class="g-recaptcha" id="rcaptcha" name="googlecaptcha" required data-sitekey="6LffZpsUAAAAAEC_KyN4KauhSSmKdRf9SVR5aVJD" data-callback="correctCaptcha"></div>
      </td>
    </tr>
    <tr>
      <td><input type="submit" name="submit" value="SUBMIT INQUIRY" id="submit"></td>
    </tr>
  </table>
</form>
javascript php forms recaptcha
1个回答
0
投票

我试过这个,它对我有用:

您有一个“数据回调”属性

<div class="g-recaptcha" id="rcaptcha" name="googlecaptcha" required data-sitekey="YOUR KEY" **data-callback="correctCaptcha"**></div>

只需创建一个名为correctCaptcha的函数

var recaptchachecked=false; 
function correctCaptcha() {
    recaptchachecked = true;
}

然后使用您的表单,直到您验证recaptchachecked变量是否为真,然后继续。

<form method="post" onsubmit="return isreCaptchaChecked(event)">
..
..
</form>

function isreCaptchaChecked()
{
  e.preventDefault();
  return recaptchachecked;
}

我希望这可以帮助你。

© www.soinside.com 2019 - 2024. All rights reserved.