简体   繁体   中英

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.

Clicking the forms submit button will either console.log( $(this) ); #form1 or #form2 depending which one was clicked. 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. 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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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