Simple Express Server for invisible reCaptcha server-side validation. Works nicely for static websites, in my case — a Jekyll website hosted on GitHub Pages.
RECAPTCHA_SECRET
and enter your secret key in the value fieldhead
of your html template: <script src='https://www.google.com/recaptcha/api.js'></script>
callback-funtion
to onSubmit
.function onSubmit(token) {
submitForm();
}
function submitForm(){
console.log('Initialize Server-Side Validation');
// Note that we grab the value of '#g-recaptcha-response' and not just '#g-recaptcha' var captcha = document.querySelector('#g-recaptcha-response').value;
fetch('YOUR HEROKU APP URL HERE', { method:'POST', headers: { 'Accept': 'application/json, text/plain, /', 'Content-type':'application/json' }, body:JSON.stringify({captcha: captcha}) }) .then((res) => res.json()) .then((data) => { console.log(data.success); if( data.success === true ){ document.getElementById("my-form").submit(); } }); }