for solution:
Automatically bind the challenge to a button
my application works as expected but
Programmatically invoke the challenge
token is always null.
simply I applied this answer:
/a/60067347/492258
<script src="https://www.google.com/recaptcha/api.js?render=mykey"></script>
<script>
grecaptcha.ready(function() {
document.getElementById('contactform').addEventListener("submit", function(event) {
event.preventDefault();
grecaptcha.execute('mykey', {action: 'homepage'}).then(function(token) {
document.getElementById("googletoken").value= token;
document.getElementById('contactform').submit();
});
}, false);
});
</script>
when I used ip such as
127.0.0.1 or prod ip
token returned is non empty string.
but on domain such as
localhost or prod domain
it is always null.