问题
I am getting below mentioned error in Browser Console. I have used Contact form 7 and Google Captcha in wordpress site.
(1) Uncaught Error: ReCAPTCHA placeholder element must be empty (2) Uncaught error: invalid recaptcha client id: undefined
Can please assist me to fix these issues.
回答1:
Remove this from the <head></head>
. It’s redundant.
<script src='https://www.google.com/recaptcha/api.js'></script>
回答2:
This is old, and might be a duplicate, but this is the page I found trying to solve my problem, so I figured I'd add something towards an answer here.
I was getting the "ReCAPTCHA placeholder element must be empty" error, and it was because the recaptcha script was being called multiple times. I was able to resolve this with a custom callback on the recaptcha's onload event:
var recaptchacalls = 0;
var onloadCallback = function(e) {
grecaptcha.render('cap-' + recaptchacalls, {
'sitekey' : '<SITE_KEY_HERE>'
});
recaptchacalls++;
};
Note the count of how many times the script is called, using that as a unique identifier for the specific container that we need to be empty.
I would venture a guess that the other error is related, non-specific identifiers in multiple calls resulting in actions being attempted on the wrong object.
来源:https://stackoverflow.com/questions/37297348/uncaught-error-recaptcha-placeholder-element-must-be-empty