Go to the reCAPTCHA website:
Sign in with your Google Account:
Register a New Site:
Choose reCAPTCHA Type:
Add Domains:
Accept reCAPTCHA Terms of Service:
Get API Keys:
Add the following script to your HTML just before the closing </head> tag:
html<head>
<!-- Other head elements -->
<script src="https://www.google.com/recaptcha/api.js" async defer></script>
</head>
Place the reCAPTCHA widget where you want the checkbox to appear in your HTML form:
html<form action="your_form_processing_script.php" method="post">
<!-- Your form fields go here -->
<div class="g-recaptcha" data-sitekey="YOUR_SITE_KEY"></div>
<input type="submit" value="Submit">
</form>
Replace "YOUR_SITE_KEY" with the actual Site Key you obtained.
Add the reCAPTCHA script to your HTML:
html<head>
<!-- Other head elements -->
<script src="https://www.google.com/recaptcha/api.js" async defer></script>
</head>
Add the reCAPTCHA widget to your form:
html<form action="your_form_processing_script.php" method="post">
<!-- Your form fields go here -->
<button class="g-recaptcha"
data-sitekey="YOUR_SITE_KEY"
data-callback="onSubmit"
data-badge="inline">Submit</button>
</form>
Replace "YOUR_SITE_KEY" with the actual Site Key you obtained.
Verify reCAPTCHA on the server-side when processing the form submission. Send a request to Google's reCAPTCHA API to validate the user's response.
Here is a simplified example in PHP:
php<?php
// your_form_processing_script.php
$recaptcha_secret = "YOUR_SECRET_KEY";
$response = $_POST['g-recaptcha-response'];
$verify_url = "https://www.google.com/recaptcha/api/siteverify?secret={$recaptcha_secret}&response={$response}";
$verify = file_get_contents($verify_url);
$result = json_decode($verify);
if ($result->success) {
// Process the form submission
// ...
} else {
// Handle failed reCAPTCHA verification
// ...
}
?>
Replace "YOUR_SECRET_KEY" with your actual Secret Key.
Subscribe our newsletter for coupon, offer and exciting promotional discount..