【问题标题】:how to validate google reCaptcha on submit button如何在提交按钮上验证 google reCaptcha
【发布时间】:2015-11-17 03:44:57
【问题描述】:

在 Joomla 3 上,我在表单页面上添加了新的 Google reCaptcha,但 Google reCaptcha 没有通过提交按钮进行验证。虽然 reCaptcha 就在表单页面上,但我仍然可以在不勾选复选框的情况下提交表单。基本上,提交按钮不会验证/链接到 reCaptcha。

按照 google reCaptcha 的指示,我做了以下操作:

<script type="text/javascript" src='https://www.google.com/recaptcha/api.js'></script>

然后将reCaptcha div放在我要显示的表单页面中:

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

以及提交按钮代码如下:

<button type="button" class="btn btn-success" onclick="Joomla.submitbutton('payment')"><?php echo JText::_('COM_JKPAYMENT', true); ?></button>  

那么你能告诉我,我需要设置什么条件才能使用 reCaptcha 验证表单提交。

【问题讨论】:

标签: php joomla3.0 recaptcha


【解决方案1】:

您需要调用 grecaptcha.getResponse()。 我的提交按钮的 id 是 btnSubmit。

<script>
    $("#btnSubmit").click(function () {
        var response = grecaptcha.getResponse();
        if(response.length != 0) //validation successful
           Joomla.submitbutton('payment');
        else
         //validation failed
    });
</script>

【讨论】:

    猜你喜欢
    • 2015-02-11
    • 2016-03-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-20
    • 1970-01-01
    • 2015-12-02
    相关资源
    最近更新 更多