【问题标题】:Can submit contact form without google recaptcha v2 validation可以在没有 google recaptcha v2 验证的情况下提交联系表单
【发布时间】:2019-04-08 23:53:06
【问题描述】:

我在 php 中使用了联系表格,并在其上添加了 google recaptcha。但我可以在没有重新验证验证的情况下提交表单。我怎样才能根据需要制作这个rec​​aptcha。我已经尝试了一些解决方案,但没有一个对我有用。感谢您的回答,谢谢

<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】:

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

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

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

希望对你有帮助。

【讨论】:

  • 我已经尝试过了,但是当我点击提交按钮时,无论验证码是否被选中,都没有任何反应。就好像我在点击空白处一样。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-03-12
  • 2014-05-11
  • 2015-02-11
  • 2015-10-14
  • 2015-12-29
  • 2015-05-13
  • 1970-01-01
相关资源
最近更新 更多