I am trying to implement Google recaptcha V3 with pure javascript and PHP, because I don't want to use heavy jQuery, and I don't know much about it.
But I didn't understand what 'execute()' method was while implementing it:
window.addEventListener('DOMContentLoaded', function()
grecaptcha.execute('XXXXXXXXXXXXXXX', {action: 'homepage'}).then(function(token) {
document.getElementById('g-recaptcha').value = token;
});
});
I replaced '.ready()' method with addEventListener(), but I could not find what 'execute()' is.
Also I cannot get to know what 'grecaptcha' is, which was shown on the Google's example. (I didn't find where it was declared yet, on the example)
My Error (in javascript console) is :
Uncaught ReferenceError: grecaptcha is not defined
My form is defined like this:
<form method="post" action="reaction.php" id="tox" name="frm1">
...
<input type="hidden" id="g-recaptcha" name="g-recaptcha">
...
</form>
My HTML header is defined like this:
<header>
<script src="https://www.google.com/recaptcha/api.js?render=xxxxxxxxxxx"></script>
</header>
What is wrong in the code and what code should I add to declare 'grecaptcha'?
Thanks for your answer in advance.