You are going to need recaptcha keys to get started on this. Get it from Google here.
Step 1: JavaScript
Add this JavaScript code between your head tags using script tag or include a seperate .js file in head tags.
grecaptcha.ready(function () {
grecaptcha
.execute("YOUR_RECAPTCHA_SITE_KEY", { action: "contact" })
.then(function (token) {
var recaptchaResponse = document.getElementById("recaptchaResponse");
recaptchaResponse.value = token;
});
});
Step 2: HTML form
Add this line after your submit button but before the form tag ends.
Step 3: PHP
Use this code for server side integration.
score >= 0.5) {
// Verified - send email
} else {
// Not verified - show form error
}
} ?>
Credit: stevencotterill. Google has nice guides for client side and server side integration as well.
examples form recaptcha spam WordPress