doujia1871 2015-08-23 18:37
浏览 186

如何在提交按钮上验证谷歌reCaptcha

On Joomla 3, I have added the new Google reCaptcha on the form page, but the Google reCaptcha doesn't validate with the submit button. Though reCaptcha is right there on the form page, I can still submit the form without ticking the checkbox. Basically the submit button doesn't validate/link up with the reCaptcha.

As per google reCaptcha direction, I have done the following:

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

And then place the reCaptcha div in the form page where I want to show:

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

And the submit button code in the following:

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

So can you tell me, what condition I need to set so that the Form submit is validate with the reCaptcha.

  • 写回答

1条回答 默认 最新

  • doujiao4705 2018-07-05 13:50
    关注

    You need to call grecaptcha.getResponse(). The id for my submit button is btnSubmit.

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

报告相同问题?

悬赏问题

  • ¥15 在获取boss直聘的聊天的时候只能获取到前40条聊天数据
  • ¥20 关于URL获取的参数,无法执行二选一查询
  • ¥15 液位控制,当液位超过高限时常开触点59闭合,直到液位低于低限时,断开
  • ¥15 marlin编译错误,如何解决?
  • ¥15 有偿四位数,节约算法和扫描算法
  • ¥15 VUE项目怎么运行,系统打不开
  • ¥50 pointpillars等目标检测算法怎么融合注意力机制
  • ¥20 Vs code Mac系统 PHP Debug调试环境配置
  • ¥60 大一项目课,微信小程序
  • ¥15 求视频摘要youtube和ovp数据集