Current File : /var/www/html/process-form.php |
<html>
<head>
<script src="https://www.google.com/recaptcha/api.js?render=6LekLRwmAAAAAF6ubqfiXStSUHb5mA8eslZ7RSiz"></script>
</head>
<form id="myForm" method="POST" action="process-form.php">
<!-- Your form fields -->
<input type="text" name="name" placeholder="Your Name" required>
<input type="email" name="email" placeholder="Your Email" required>
<!-- Add a hidden field for the reCAPTCHA response -->
<input type="hidden" name="recaptcha_response" id="recaptchaResponse">
<!-- Submit button -->
<button type="submit">Submit</button>
</form>
<script>
// Handle form submission
document.getElementById("myForm").addEventListener("submit", function(event) {
event.preventDefault(); // Prevent the form from submitting
// Call the function to execute reCAPTCHA validation
validateRecaptcha();
});
// Execute reCAPTCHA validation
function validateRecaptcha() {
grecaptcha.ready(function() {
grecaptcha.execute('6LekLRwmAAAAAF6ubqfiXStSUHb5mA8eslZ7RSiz', {action: 'submit'}).then(function(token) {
// Add the reCAPTCHA response to the hidden field
document.getElementById("recaptchaResponse").value = token;
// Submit the form
document.getElementById("myForm").submit();
});
});
}
</script>
</html>