2👍
I encountered the same problem today.
It seems the javascript snippet is incorrect:
- Your element needs an id. (Mine is “cform” now.)
- CreateElement does not exist, the “c” is lower case.
- I could not create an element with attributes, I had to do it in several steps.
I don’t usually code in javascript so I don’t know the best practices, but here is what worked for me:
<script src='https://www.google.com/recaptcha/api.js?render=<KEY>'></script>
<script>
grecaptcha.ready(function() {
grecaptcha.execute(<KEY>, {action: 'contact'})
.then(function(token) {
ginput = document.createElement('input');
ginput.type = "hidden";
ginput.name = "g-recaptcha-response";
ginput.value = token;
document.getElementById("cform").appendChild(ginput);
});
});
</script>
Source:stackexchange.com