123ArticleOnline Logo
Welcome to 123ArticleOnline.com!
ALL >> Education >> View Article

Add Google Recaptcha V3 In Php Contact Form

Profile Picture
By Author: sanjeev rai
Total Articles: 37
Comment this article
Facebook ShareTwitter ShareGoogle+ ShareTwitter Share

Google has released Google reCAPTCHA v3, a new and improved version of recaptcha. It improves the security of your web forms against spam bots and other sorts of abuse. The spam score is used by Google reCAPTCHA v3, which means that the reCAPTCHA v3 API delivers the spam score of each request based on the user activity.


How to add Google reCAPTCHA V3 in PHP Contact form

In comparison to Google reCAPTCHA v2, this reCAPTCHA v3 is more easier to use because the user does not have to click on the checkbox, which is required in Google reCAPTCHA v2. It simply calculates a spam score based on the supplied data and user activity and determines whether the action is spam or not.

In this PHP TUTORIAL, we'll look at how to use a contact form to implement Google reCAPTCHA v3 in PHP. If you have a contact form or any other type of form on your website and are concerned about spam, you've come to the correct spot. We recommend that you follow this guide all the way through so that you have a thorough understanding of how to defend your forms from spambot attacks.

You can see a demo of Google recaptcha v3 ...
... here, and I've prepared a functioning code so you can quickly download Google recaptcha v3 code and incorporate it into your project or application.

Google reCAPTCHA v3 in PHP: Step to step explanation
Developers are paying greater attention to the newest version of Google reCAPTCHA v3 because it eliminates one extra click in your HTML forms. In your HTML forms, this reCAPTCHA v3 will not display any kind of captcha. This implies it is hidden and will not appear in your frontend forms on the web page; it can only be seen in the right bottom corner.

The spam score is returned by Google reCAPTCHA v3 on each request without the end-user having to do anything. Because Google reCAPTCHA v3 is transparent and does not interfere with user engagement, we may use it anywhere on the website and in user interactions, but it works best when we are capturing user input.

To use Google reCAPTCHA V3 in a PHP Contact form, follow the steps below.

From the Google reCAPTCHA Admin panel, generate a Site key and a Secret key.
In PHP, create a simple contact form.
Create a PHP file that uses the Google reCAPTCHA V3 API to validate the form.
In PHP, create a simple contact form.

To demonstrate Google reCAPTCHA, we constructed a simple contact form in HTML and Bootstrap. We supply a js file that may be used to contact the Google reCAPTCHA API from an HTML form.

We'll replace YOUR SITE KEY> with your produced site key below. We also use recaptcha response as a hidden field, and we'll use a javascript call to replace the value of this input field during runtime. As a result, the Google reCAPTCHA API generates a one-of-a-kind key and saves it in this input field. This value will be used in the PHP file to validate the input and calculate the spam score.


Google reCAPTCH V3 Example








body{background-color:#f4f8fa;}




Demo of Integrate Google reCAPTCHA V3 in PHP




Name:



Email:



Comment:




Note: This form is protected by Google reCAPTCHA.


The Javascript code

grecaptcha.ready(function () {

grecaptcha.execute('', { action: 'submit' }).then(function (token) {

var recaptchaResponse = document.getElementById('recaptchaResponse');


recaptchaResponse.value = token;

We'll now use AJAX to call the PHP file and provide all of the contact form's values to it. As a result, all of the information will be validated, and we will receive a response based on the Google reCAPTCHA API valiadation and spam score.

$('form').submit(function(event) {

event.preventDefault(); //Prevent the default form submission

grecaptcha.ready(function () {

grecaptcha.execute('', { action: 'submit' }).then(function (token) {

var recaptchaResponse = document.getElementById('recaptchaResponse');

recaptchaResponse.value = token;

// Making the simple AJAX call to capture the data and submit

$.ajax({

url: 'submit_enquiry.php',

type: 'post',

data: $('form').serialize(),

dataType: 'json',

success: function(response){

var error = response.error;

var success = response.success;

if(error != "") {

$('#alert_message').html(error);

}

else {

$('#alert_message').html(success);

}

},

error: function(jqXhr, json, errorThrown){

var error = jqXhr.responseText;

$('#alert_message').html(error);

}

});

});

});

});

Create a PHP file(submit_enquiry.php)
This PHP file takes all of the information from the contact form and sends it to Google's reCAPTCHA API. You must replace YOUR SECRET KEY> with the secret key you generated. To generate the spam score, we now use the reCAPTCHA API and send these variables to it.

Now we'll go over how to implement Google reCAPTCHA V3 to a PHP Contact form step by step. To prevent spam, I recommend using this reCAPTCHA in your web forms or in your application.

https://www.phptpoint.com/

More About the Author

We offer an online free tutorial on many web technologies such as php, laravel, Codeigniter, MySQL and so on web technologies

Total Views: 409Word Count: 1732See All articles From Author

Add Comment

Education Articles

1. Generative Ai Courses Online With Industry Projects
Author: golla kalyan

2. Microsoft Fabric Course In Ameerpet | Online Training
Author: Subahan

3. Dental Veneers In Chennai – A Modern Option For A Confident Smile
Author: MAHESH

4. Agentic Ai With Copilot Studio Training | Copilot Studio Training
Author: Visualpath

5. Digital Smile Design In Velachery – A Modern Approach To Smile Enhancement
Author: MAHESH

6. Smile Design In Velachery – Personalized Cosmetic Dentistry For A Confident Smile
Author: MAHESH

7. Best Saloon In Anna Nagar East – Your Guide To Professional Beauty Care
Author: prasant

8. Cysa+: Exam Details, Skills, Cost And Preparation Guide
Author: Passyourcert

9. Salesforce Ai Course | Salesforce Devops Copado Ai Training
Author: Vamsi Ulavapati

10. Ai Engineering For Forward Deployed Engineer Course | Fde
Author: visualpath

11. Ccoa Certification: Complete Guide To The Isaca Cybersecurity Operations Analyst Credential
Author: Passyourcert

12. Cia Challenge Certification 2026: Complete Exam And Training Guide
Author: NYTCC

13. Comptia Network+ Certification: Exam, Cost & Training
Author: Passyourcert

14. How Ai Is Changing The Skills Employers Want In Finance
Author: Future Skills Research Team

15. Digital Smile Design In Velachery – Modern Technology For A Personalized Smile
Author: MAHESH

Login To Account
Login Email:
Password:
Forgot Password?
New User?
Sign Up Newsletter
Email Address: