简体   繁体   English

如何在页面上仅验证一个验证码

[英]How to validate only one captcha on a page

I have two forms on a page whose inputs I want validate and both have captchas which I also want to validate.我在一个页面上有两个 forms 我想验证其输入,并且两者都有我也想验证的验证码。

Clicking the forms submit button will either console.log( $(this) );单击 forms 提交按钮将要么 console.log( $(this) ); #form1 or #form2 depending which one was clicked. #form1 或 #form2 取决于单击了哪一个。 With that I can safely target the respective inputs, but with captcha I dont know if you can do that.有了它,我可以安全地定位相应的输入,但是使用验证码我不知道你是否可以做到这一点。 I'm using the below code that works when theres only one captcha.我正在使用以下代码,该代码在只有一个验证码时有效。 My guess is, because it isnt using $(this) or something similar, it uses both forms recaptcha and breaks.我的猜测是,因为它没有使用 $(this) 或类似的东西,所以它同时使用了 forms recaptcha 和中断。 In what way could I only trigger the captcha that is inside the currently submitted form?我只能以什么方式触发当前提交的表单中的验证码?

if (grecaptcha && grecaptcha.getResponse().length > 0) {
  //the recaptcha is checked
  reCaptcha = true;
} else {
  //The recaptcha is not cheched
  reCaptcha = false;
  $(this).find('.g-recaptcha').addClass('captcha-error');
} 

You should not need more than 1 captcha per page.每页不需要超过 1 个验证码。

The purpose of captcha's is to protect against bots.验证码的目的是防止机器人。 Once someone has solved a captcha, they have earned the trust of the website insofar as they are not a bot.一旦有人解决了验证码,他们就赢得了网站的信任,因为他们不是机器人。

Requiring users to solve more than one is entirely pointless.要求用户解决多个问题是完全没有意义的。 My suggestion is to place the one captcha in a convenient spot, such that it clearly applies to both captchas.我的建议是将一个验证码放在一个方便的位置,这样它就可以清楚地适用于两个验证码。

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

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