craft-recaptcha icon indicating copy to clipboard operation
craft-recaptcha copied to clipboard

reCaptcha not stopping a form from sending?

Open bleuchill opened this issue 6 years ago • 5 comments

I was able to install and have reCaptcha show successfully on the footer of a site I'm editing (but did not develop). The form—pixelandtonic's contact form—is meant to get a visitor's name and email address.

However, the form still validates even though I didn't check the reCaptcha panel. I only have {{craft.recaptcha.render('dark', 'compact')}} on the page. I tried to include the saveuser code from the readme, but I don't think it's necessary for what I use the form for.

What am I missing?

bleuchill avatar Aug 30 '18 02:08 bleuchill

How does this work? I am having same issue. Form just submits. I assume we need the server side response object but isn't that part of this plugin?

bgarrant avatar Sep 01 '18 12:09 bgarrant

Same issues here, anyone ever got this to work?

eheiser avatar Jan 07 '19 16:01 eheiser

Same here

theurbanu avatar Jan 13 '19 01:01 theurbanu

Same.

brandondeweese avatar Jan 15 '19 20:01 brandondeweese

Go to craft/plugins/contactform/controllers/ContactFormController.php at line 34 adding:

// required to install craft recaptcha plugin
        $captcha = craft()->request->getPost('g-recaptcha-response');
        $verified = craft()->recaptcha_verify->verify($captcha);
        if(!$verified)
        {
            //Uh oh...its a robot. Don't process this form!
            craft()->userSession->setError('Please check the recaptcha, to prove that you are not a robot!');
            $errorMsg = array(
                'message' => $message,
				'recaptchamessage' => "Please verify your recaptcha"
			);
			$this->renderTemplate("contact", $errorMsg, true, true);
        } 

My contact page is {{ siteUrl }}contact, please change it based on the template you wanted to show.

And the in html/twig, you can do

{% if recaptchamessage is defined %}<div class="errors">{{ recaptchamessage }}</div>{% endif %}

to grab the error.

This is temporary fix, and the important thing is its working. Important notice: if you uninstall plugin recaptcha, and you have contact form running. When you submit the contact form, you will definitely get a 500 error.

xhuang9 avatar Dec 18 '19 05:12 xhuang9