Skip to content
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

Open
andreiciulinaru opened this issue Feb 22, 2021 · 5 comments
Open

Missing reCAPTCHA validation #2

andreiciulinaru opened this issue Feb 22, 2021 · 5 comments

Comments

@andreiciulinaru
Copy link

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 {

@webdeveloper778
Copy link

Hello,
Could someone please tell me where the above snippet of code should go in the recaptcha.php file? I tried it in a few places in the php file but doesn't seem to work.

@jaydadarkar
Copy link

jaydadarkar commented Jul 24, 2023

@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 }

@webdeveloper778
Copy link

webdeveloper778 commented Jul 24, 2023 via email

@dwh2427
Copy link

dwh2427 commented Apr 5, 2024

@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.
Thanks,
David

@jaydadarkar
Copy link

Hi Dave,
Not sure if this repo is maintained, so even if I submit a pull request, less likely it will get accepted. Would request you to refer my comment above and lmk.
Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants