-
Notifications
You must be signed in to change notification settings - Fork 79
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Missing reCAPTCHA validation #2
Comments
Hello, |
@webdeveloper778
Remove the div that has id="re-captcha" and add the following to the submit button
In you contact.php, check if you are getting g-recaptcha-response by dumping $_POST. Once, everything is in place, in the head after opening php tags, add the following Before you perform any operation and after validation of inputs, initialize the captcha.
|
Hey,
Thanks for the reply. But as it was many years ago I moved over to
Wordpress & found a contact form plugin that supports recaptcha. But I do
appreciate the time you have taken and will keep this code for future use.
Regards
Neil
…On Mon, 24 Jul 2023 at 08:55, Jay Dadarkar ***@***.***> wrote:
@webdeveloper778 <https://github.com/webdeveloper778>
You have 2 files, index.html and contact.php
Add this script to the bottom in script tag after validation code
function onSubmit(token) {
document.getElementById("main-offer-form").submit(); }
Remove the div that has id="re-captcha" and add the following to the
submit button
class="g-recaptcha" data-sitekey="reCAPTCHA_site_key"
data-callback='onSubmit' data-action='submit'
In you contact.php, check if you are getting g-recaptcha-response by
dumping $_POST.
Once, everything is in place, in the head after opening php tags, add the
following
require_once('recaptchalib.php');
Before you perform any operation and after validation of inputs,
initialize the captcha.
$recaptcha = new ReCaptcha('YOUR_SECRET_KEY'); $recaptcha =
$recaptcha->verifyResponse($_SERVER['REMOTE_ADDR'],
$_POST['g-recaptcha-response']); if($recaptcha->success){ // Success }
else{ // Failed }
—
Reply to this email directly, view it on GitHub
<#2 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AWD67TKJXQA2LL4ZZTTR373XRYTANANCNFSM4YA7QLTA>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
@jaydadarkar or anyone else here, are you able to update the code to reflect these changes? I'm not so savvy and got everything working only to find the recaptcha isn't working so the form is broken. |
Hi Dave, |
Dhanybhad for your template. It's looking really good.
I noticed there is no validation on reCAPTCHA user's input when the form is submitted.
So, you can submit the form without validating the quizz.
I tweaked it to include a check when receiving the POST request, enough to avoid spammers.
if(!isset($_POST['g-recaptcha-response']) || empty($_POST['g-recaptcha-response'])) {
echo 'reCAPTHCA verification failed, please try again.'; } else {
The text was updated successfully, but these errors were encountered: