简体   繁体   English

如何在提交按钮上验证Google reCaptcha

[英]how to validate google reCaptcha on submit button

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. 在Joomla 3上,我在表单页面上添加了新的Google reCaptcha,但是Google reCaptcha不能使用“提交”按钮进行验证。 Though reCaptcha is right there on the form page, I can still submit the form without ticking the checkbox. 尽管reCaptcha就在表单页面上,但是我仍然可以提交表单而无需勾选复选框。 Basically the submit button doesn't validate/link up with the reCaptcha. 基本上,提交按钮不会验证/链接到reCaptcha。

As per google reCaptcha direction, I have done the following: 按照google reCaptcha的指示,我已执行以下操作:

<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: 然后将reCaptcha div放在要显示的表单页面中:

<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. 因此,您能告诉我,我需要设置什么条件,以便使用reCaptcha验证表单提交。

You need to call grecaptcha.getResponse() . 您需要调用grecaptcha.getResponse() The id for my submit button is btnSubmit. 我的提交按钮的ID为btnSubmit。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM