Php jQuery验证插件为Google Recaptcha V.2添加一条规则
我有一个注册页面,其中使用了Google Recaptcha V.2。我想使用jQuery验证插件为enter-Recaptcha添加一条规则。在注册页面中,显示了以下代码,用于显示Google Recaptcha:Php jQuery验证插件为Google Recaptcha V.2添加一条规则,php,jquery,jquery-validate,recaptcha,Php,Jquery,Jquery Validate,Recaptcha,我有一个注册页面,其中使用了Google Recaptcha V.2。我想使用jQuery验证插件为enter-Recaptcha添加一条规则。在注册页面中,显示了以下代码,用于显示Google Recaptcha: <?php if(!$this->K2Params->get('recaptchaV2')): ?> <label class="formRecaptcha"><?php echo JText::_('K
<?php if(!$this->K2Params->get('recaptchaV2')): ?>
<label class="formRecaptcha"><?php echo JText::_('K2_ENTER_THE_TWO_WORDS_YOU_SEE_BELOW'); ?></label>
<?php endif; ?>
<div id="recaptcha" name="recaptcha" class="<?php echo $this->recaptchaClass; ?>"></div>
但这条规则并不适用于谷歌Recaptcha。你能帮我们解决这个问题吗?哦,我添加了hiddenRecaptcha的规则,并添加了id和名称为“hiddenRecaptcha”的隐藏输入。正确的代码如下:
<?php if(!$this->K2Params->get('recaptchaV2')): ?>
<label class="formRecaptcha"><?php echo JText::_('K2_ENTER_THE_TWO_WORDS_YOU_SEE_BELOW'); ?></label>
<?php endif; ?>
<div id="recaptcha" name="recaptcha" class="<?php echo $this->recaptchaClass; ?>"></div>
<input type="hidden" class="hiddenRecaptcha required" name="hiddenRecaptcha" id="hiddenRecaptcha" />
现在,验证码规则已经生效。在发布新问题之前,请使用。我正在寻找类似的问题,但这些问题并不是我所需要的。所以我问了我的问题,除非你做错了,否则完全一样。
<?php if(!$this->K2Params->get('recaptchaV2')): ?>
<label class="formRecaptcha"><?php echo JText::_('K2_ENTER_THE_TWO_WORDS_YOU_SEE_BELOW'); ?></label>
<?php endif; ?>
<div id="recaptcha" name="recaptcha" class="<?php echo $this->recaptchaClass; ?>"></div>
<input type="hidden" class="hiddenRecaptcha required" name="hiddenRecaptcha" id="hiddenRecaptcha" />
jQuery(($)=>{
$().ready(()=>{
$("#josForm").validate({
ignore: ".ignore",
rules: {
name: {
required: true,
minlength: 3
},
password: {
required: true,
minlength: 7
},
email: {
required: true,
email: true
},
hiddenRecaptcha: {
required: function() {
if(grecaptcha.getResponse() == '') {
return true;
} else {
return false;
}
}
},
},
messages: {
name: {
required: "enter your name",
minlength: "no less than 3 symbols"
},
password: {
required: "enter the password",
minlength: "no less than 7 symbols"
},
email: "enter your email",
email: {
required: "enter your email"
},
},
});
});
});