So we are using this recaptcha module on our contact form to show the Google Recaptcha (checkbox one). As soon as someone fills in the form and submits the page crashes and submission is not made. Logs show this error:

Error: Class 'ReCaptcha\ReCaptcha' not found in recaptcha_captcha_validation() (line 162 of /srv/bindings/60c14a3de43141b691621309dd11eca8/code/modules/contrib/recaptcha/recaptcha.module)

Comments

Ahmed.Raza created an issue. See original summary.

timme77’s picture

Same problem here. I'm on Drupal 8.8.5.

drupal.ninja03’s picture

I am using Drupal core 8.8.6, PHP 7.2 and I am unable to reproduce this error. Please provide the steps to reproduce.

stevensf’s picture

Same problem...

Drupal v8.8.5 - PHP 7.3 - Webform 8.5.15 - Captcha 8.1.1 - reCaptcha 8.3.0

sajid_007’s picture

StatusFileSize
new61.96 KB

Method 1
First simply install recaptcha module from here https://www.drupal.org/project/recaptcha or you can install it using git after that place this attached "google" folder inside vendor folder of your drupal directory it will fix your issue.

Method 2
Second method is you can just simply install recaptcha module using composer it will also fix your issue.

dskyo’s picture

Steps to reproduce on drupal 8.9
Add CAPTCHA module from https://www.drupal.org/project/captcha and install
Add reCAPTCHA module from https://www.drupal.org/project/recaptcha and install
Configure CAPTCHA to use reCAPTCHA as default
Add reCAPTCHA to some of the forms. For example login form or contact form
Try submitting the form as Anonymous

drupal.ninja03’s picture

Hi @dskyo,

I installed both the captcha & Recaptcha modules and enabled it for the login form. I was able to use the Recaptcha on the login form successfully without any such error.

Drupal 8.8.9, PHP 7.2, Captcha 8.x-1.1, ReCaptcha 8.x-3.x

kaaa’s picture

As far as I can see, a bunch of require_once directives is missing in ReCaptcha 8.x-3.x in recaptcha.module in the very preamble of the file (comparing to ReCaptcha 8.x-2.5):

require_once dirname(__FILE__) . '/recaptcha-php/src/ReCaptcha/ReCaptcha.php';
require_once dirname(__FILE__) . '/recaptcha-php/src/ReCaptcha/RequestMethod.php';
require_once dirname(__FILE__) . '/recaptcha-php/src/ReCaptcha/RequestParameters.php';
require_once dirname(__FILE__) . '/recaptcha-php/src/ReCaptcha/Response.php';
require_once dirname(__FILE__) . '/src/ReCaptcha/RequestMethod/Drupal8Post.php';

Adding those directives solves the problem.

bamlhes’s picture

#5 worked for me by ( second method ) composer , thanks .

jeffc518’s picture

Same issue here - Drupal v8.8.2, PHP 7.3, Webform 8.x-5.12

I'm looking at line 162 of recaptcha.module:

// Use Drupal::httpClient() to circumvent all issues with the Google library.
  $recaptcha = new ReCaptcha($recaptcha_secret_key, new Drupal8Post());

I can't actually find a "ReCaptcha" class, my IDE complains about it (Undefined class). This site is on Pantheon with their standard one click update upstream so it's not something I'm managing with Composer. Any other patches in the works? : )

jeffc518’s picture

FYI, I found this SO answer helpful to get some more context on the other answers here: https://stackoverflow.com/questions/29056472/google-recaptcha-2-fatal-er...

As much as I'd like to be using Composer, I wasn't given the option with this project so I need to take an extra step and download the Recaptcha library separately. If anyone has a better option though please let me know.

jacob.herrera’s picture

For anyone who doesn't have access to composer and needs a quick fix, I was able to get my reCaptcha working again by:

  1. unzipping the zip in #5 into my vendor folder
  2. downloading 8.x-2.5 from the reCaptcha module page and copying the 'recaptcha-php' folder & its contents into the root of the reCaptcha module
  3. adding the five require_once lines in #8 to line 3 of recaptcha.module

I was able to successfully submit forms with reCaptcha enabled again, but I'm sure there's a more correct fix for those without composer out there somewhere.

ahmed.raza’s picture

There should be a correct fix for this who install modules via drush. Getting this exact same issue again on a new Drupal project.

huntertrammell’s picture

I can confirm #12 worked for me, I also did not have access to composer and ran into the same error! Using Drupal 8.7.6 with module ver 8x-3.0

estoyanov’s picture

I can confirm #12 worked for me as well, I am using Drupal 9.0.3 with module version 8x-3.0.

MikheevDesign’s picture

I can confirm #12 worked for me as well, I am using Drupal 9.0.6 with module version 8x-3.0.

ferst’s picture

I can confirm #12 worked for me as well, I'm using Drupal 9.0.6 with ReCaptcha 8.x-3.0.

countach’s picture

#12 doesn't work for me - it's possible to submit the form without checking the captcha :(

//update - sorry, I forgot to upload the google dir into vendor dir :P It does work!

froboy’s picture

I ran into a similar issue, running into failing forms and Error: Class 'ReCaptcha\RequestMethod\Drupal8Post' not found in my logs.

I was able to resolve the issue by changing the use statement in my custom module:

- use ReCaptcha\RequestMethod\Drupal8Post;
+ use Drupal\recaptcha\ReCaptcha\RequestMethod\Drupal8Post;

I haven't dug in, but it seems like this is just the result of some namespace changes or maybe the new use of composer in the move from 2.x to 3.x.

deslack’s picture

I can confirm #12 also worked for me, fixing the same error. Since i'm on a shared host, composer was unavailable to me. Using Drupal 8.9.8 with module ver 8.x-3.0

mylocaltrades’s picture

I can also confirm that #12 worked for me, fixing the same error. Using composer didn't resolve this issue for me on a number of sites. This was using Drupal 8.9.10 with module version 8.x-3.0

RazedandRisen’s picture

I have the same error and have tried the solution in #5 and still get Error:

Class 'ReCaptcha\ReCaptcha' not found in _recaptcha_v3_verify_captcha_response() (line 287 of modules/recaptcha_v3/recaptcha_v3.module).

My ReCaptcha folder does not have another ReCaptcha inside it. So I'd imagine since I don't have this structure "ReCaptcha\ReCaptcha" is why I'm getting this error.

I've downloaded the latest version of ReCaptcha from the drupal mod site and installed it through the "Extend" tab in the admin.

Am I missing something?

Drupal 9.1.0 and php version 7.3.15

lomale@bluewin.ch’s picture

Component: reCAPTCHA V2 » reCAPTCHA V3

I had the same problem. Same log error

Running Drupal-Version 8.9.12 PHP 7.4.13
reCAPTCHA V3

I can confirm #5
Method 2
Second method is you can just simply install recaptcha module using composer it will also fix your issue.

without having to add the 5 lines of
#8

Thanks for the help on this page.

aritrika.d’s picture

StatusFileSize
new648 bytes
aritrika.d’s picture

Status: Active » Needs review
reis quarteu’s picture

I can confirm #12 worked for me as well, I am using Drupal 8.9.13, PHP 7.3.26, with module version 8.x-3.0.
However, I have tested and am pretty sure that the step #1 (unzipping the zip in #5 into my vendor folder) is not necessary: I have removed it from my web site, and the reCaptcha is working nicely.

lubwn’s picture

Installing 8-2.5 with attached patch from #24 solves an issue for me. I think version 3.0 should not be reccomended if it does not work out of the box.

cameroncrobinson’s picture

#8/#24 only work if you include the recaptcha-php folder which has been removed from the 3.x build of recaptcha. After adding that folder back recaptcha seems to be working fine (as stated in #12). And those require_once directives. What was supposed to be the replacement functionality for that folder?

KLIGGS’s picture

#5 and #24 worked for me with D8.9.13, PHP 7.4.13, recaptcha 8.x-3.0

Steps

  • Download file google.zip described under #5
  • Rename folder recaptcha to recaptcha-php inside google folder
  • Place folder recaptcha-php to /modules/recaptcha
  • Apply PATCH from #24 oder just edit manually first lines in file /modules/recaptcha/recaptcha.module

Copy this lines on top of file /modules/recaptcha/recaptcha.module, if manually editing.

<?php

require_once dirname(__FILE__) . '/recaptcha-php/src/ReCaptcha/ReCaptcha.php';
require_once dirname(__FILE__) . '/recaptcha-php/src/ReCaptcha/RequestMethod.php';
require_once dirname(__FILE__) . '/recaptcha-php/src/ReCaptcha/RequestParameters.php';
require_once dirname(__FILE__) . '/recaptcha-php/src/ReCaptcha/Response.php';
require_once dirname(__FILE__) . '/src/ReCaptcha/RequestMethod/Drupal8Post.php';
isalmanhaider’s picture

#29 worked for me!
Great explanation

cangurin limpiezas’s picture

Thanks #29 worked for me too in Drupal 9.1.4!

sajithathukorala’s picture

#29 worked but now form can submit without captcha . any idea ? this is tested for webforms .

thomaswalther’s picture

I got this error on drupal 8.8.5.

#0 /V01/modules/captcha/captcha.module(500): recaptcha_captcha_validation()
#1 [internal function]: captcha_validate()
#2 /V01/core/lib/Drupal/Core/Form/FormValidator.php(282): call_user_func_array()
#3 /V01/core/lib/Drupal/Core/Form/FormValidator.php(238): Drupal\Core\Form\FormValidator->doValidateForm()
...
luison’s picture

This is still an error. Fixed with #12 solution.

drupalfan2’s picture

I installed the recaptcha module with composer, but I still get this error:

Error: Class 'ReCaptcha\ReCaptcha' not found in recaptcha_captcha_validation() (line 162 of modules/contrib/recaptcha/recaptcha.module).

google/recaptcha has been installed to vendor dir by composer, but the error still is here.

Please commit a working patch!

drupalfan2’s picture

I added the following code lines to top of recaptcha.module to get it work:

<?php
require_once dirname(__FILE__) . '/../../../../vendor/google/recaptcha/src/ReCaptcha/ReCaptcha.php';
require_once dirname(__FILE__) . '/../../../../vendor/google/recaptcha/src/ReCaptcha/RequestMethod.php';
require_once dirname(__FILE__) . '/../../../../vendor/google/recaptcha/src/ReCaptcha/RequestParameters.php';
require_once dirname(__FILE__) . '/../../../../vendor/google/recaptcha/src/ReCaptcha/Response.php';
require_once dirname(__FILE__) . '/../../../../vendor/google/recaptcha/src/ReCaptcha/RequestMethod/Post.php';

vendor/google/recaptcha has been installed by composer, but why it is not autoloaded????

chris matthews’s picture

Priority: Major » Critical
aswathyajish’s picture

I have tried #5 and #29, but no results. After applying patch, when tried to clear cache, site breaks.

joshuautley’s picture

Duplicate. Solved using Ludwig.

Ref > https://www.drupal.org/project/recaptcha/issues/3152474

drupalfan2’s picture

We need a solution without any patch for 8.x-3.1!

It is high time for a new release.

devad’s picture

Status: Needs review » Closed (duplicate)
Related issues: +#3152474: reCAPTCHA - Ludwig integration

There is a working patch in related issue.

Review it and try to convince reCAPTCHA maintainers for commit.

Ludwig integration is the optimal way to add support for Drupal users not familiar with Composer yet. If reCAPTCHA maintainers would like to support any other method of course.

Ludwig is created and maintained by Drupal Commerce team to solve all kinds of "How can I use this module without Composer?" issues. Other approaches (Patch #24 and similar) are not recommended in D8/9.

drupalfan2’s picture

I think we need a solution that works with composer.

What is actually the problem? Why isn't the module and its dependencies installed correctly?

gumdal’s picture

Been a year since #12 was proposed, still that is the only solution for me. Moreover, composer will not work unless we have terminal access but in shared hosting environment we rarely get the terminal access. Drupal needs to consider solutions for non-composer users!

drupalfan2’s picture

Status: Closed (duplicate) » Active

I think this is NOT a ludwig problem.

webdevfreak’s picture

This issue is still active in Drupal 9 and need fixing. I have tried both options i.e composer and ludwig but no luck.

reCAPTCHA Version: 8.x-3.0

Drupal Version: 9.1.4

PHP Version: 7.4.21

Error message:
"The website encountered an unexpected error. Please try again later.
Error: Class 'ReCaptcha\ReCaptcha' not found in recaptcha_captcha_validation() (line 164 of modules/contrib/recaptcha/recaptcha.module)."

dcrellen’s picture

I stumbled upon this page after fighting this issue for 2 days. In my Drupal 9 I finally bit the bullet, learned how to use Composer (https://www.drupal.org/docs/8/modules/recaptcha-v3/installation-and-conf...) and used this command: composer require drupal/recaptcha_v3

That, magically made it all work!!!

The Recaptcha project page needs to EMPHASIZE the need to use composer to make it work.

Thanks to all for their efforts/pains

devad’s picture

Re: #46

Just in case you are not aware of... the drupal/recaptcha_v3 is a completely different Drupal module/project. This issue queue is for drupal/recaptcha module.

buddym’s picture

Following steps 2 & 3 from #12 resolved the "Error: Class 'ReCaptcha\ReCaptcha' not found in recaptcha_captcha_validation()" on Drupal 9.2.4 with CAPTCHA 8.x-1.2 and reCAPTCHA 8.x-3.0.

drupaleye’s picture

This worked for me (recaptcha 8.x-3.0 and Drupal 9.2.6):

  • (make a note of your recaptcha settings)
  • Uninstalling the recaptcha module (/admin/modules/uninstall)(module files are not removed from the modules folder)
  • Installing the Ludwig module
  • Adding a ludwig.json file inside the recaptcha module folder containing:
    {
      "require": {
        "google/recaptcha": {
          "version": "v1.2.4",
          "url": "https://github.com/google/recaptcha/archive/1.2.4.zip"
        }
      }
    }
  • clear cache
  • visiting admin/reports/packages and follow the instructions to manually download and install some google libraries inside the recaptcha module folder (including adding some new subfolders)
  • installing recaptcha module
  • reentering keys and setting for recaptcha

Voila! I officially love the Ludwig module now. Thanks devad!

devad’s picture

visiting admin/reports/packages and follow the instructions to manually download and install some google libraries inside the recaptcha module folder (including adding some new subfolders)

There is the automatic "Download and unpack missing packages" button at the top of Ludwig's Reports / Packages page. This button takes care of cache clear as well.

Note: If you are using Ludwig version prior to 8.x-1.4 it does not have the automatic "Download and unpack missing packages" button. So, update to the latest one.

There are a lot of outdated Ludwig tutorials on WEB who are explaining the manual library setup steps. But the manual download and unpack of missing packages is not needed any more. Unless your server is not allowed to connect to external links.

Read more here:

Manual library setup [obsolete]

promo-il’s picture

+1

jeeba’s picture

#49 works for me. And also it should be suggested in the Recaptcha Module that installing the library is needed. It will help a lot with this.

Jean Gionet’s picture

#49 did the trick! Thanks!

Greg Sims’s picture

#49 worked for me on Drupal core 8.9.20.

Please note getting past this error is required for us to upgrade to Drupal 9. I would think many people are seeing this error.

bas123’s picture

I just upgraded to Drupal 9.3.2 and realized the Site Login reCaptcha is throwing this error:

The website encountered an unexpected error. Please try again later.
Error: Class "ReCaptcha\ReCaptcha" not found in recaptcha_captcha_validation() (line 162 of modules/recaptcha/recaptcha.module).

recaptcha_captcha_validation() (Line: 510)
captcha_validate()
call_user_func_array() (Line: 282)
Drupal\Core\Form\FormValidator->doValidateForm() (Line: 238)
Drupal\Core\Form\FormValidator->doValidateForm() (Line: 118)
Drupal\Core\Form\FormValidator->validateForm() (Line: 588)
Drupal\Core\Form\FormBuilder->processForm() (Line: 320)
Drupal\Core\Form\FormBuilder->buildForm() (Line: 73)
Drupal\Core\Controller\FormController->getContentResult()
call_user_func_array() (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 564)
Drupal\Core\Render\Renderer->executeInRenderContext() (Line: 124)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext() (Line: 97)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 158)
Symfony\Component\HttpKernel\HttpKernel->handleRaw() (Line: 80)
Symfony\Component\HttpKernel\HttpKernel->handle() (Line: 58)
Drupal\Core\StackMiddleware\Session->handle() (Line: 48)
Drupal\Core\StackMiddleware\KernelPreHandle->handle() (Line: 106)
Drupal\page_cache\StackMiddleware\PageCache->pass() (Line: 85)
Drupal\page_cache\StackMiddleware\PageCache->handle() (Line: 48)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle() (Line: 51)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle() (Line: 23)
Stack\StackedHttpKernel->handle() (Line: 708)
Drupal\Core\DrupalKernel->handle() (Line: 19)

Drupal v 9.3.2 | PHP v 8.1 | reCaptcha v 8.x-3.0
I see several solutions here, but none seem to address Drupal ^9

I have temporarily switched default Captcha settings to "Image (from module image captcha)" and the process is working, but not when the default is set to reCaptcha!

Please advise!

Thanks!

kazaa’s picture

in Drupal 9 fix not working, still I have notice "The website encountered an unexpected error. Please try again later."

When I am logged to my profile in Durpal is ok, but for not logged users this communicate is visible after captacha approve.

Drupal core 9.1.10

devad’s picture

I can not reproduce this on clean Composer-managed D9.3.3 installation with recaptcha 8.x-3.0 or the latest 8.x-3.x-dev.

If you can reproduce the 'Class "ReCaptcha\ReCaptcha" not found' error please post the exact steps to reproduce this error.

And in your post with reproducing steps also please post all of the following data:

  1. What is your Drupal Core version?
  2. Please confirm that you are using Composer to manage your site. And post the content of your composer.json file.
  3. Please ensure that the require section of your composer.json file have this line of code: "drupal/recaptcha": "^3.0",. If it doesn't have it - please read post #61 below.
  4. Please confirm that you are not using Ludwig module and that you have Ludwig module uninstalled if you have used it previously.
  5. What are your Captcha module and Recaptcha module versions?
  6. Is your site at local environment or hosted?
  7. What is your PHP version?
  8. Post the complete log error including User, Location, Referrer and Message

The screenshots of your "CAPTCHA settings", "Form settings" and "reCAPTCHA" settings can help as well. You can hide the recaptcha keys at your screenshot of course.

bas123’s picture

@devad,

  1. Drupal Core: 9.3.5
  2. Composer Composer version 2.2.4
    composer.json:
    {
        "name": "drupal/legacy-project",
        "description": "Project template for Drupal 8 projects with composer following drupal/drupal layout",
        "type": "project",
        "license": "GPL-2.0-or-later",
        "homepage": "https://www.drupal.org/project/drupal",
        "support": {
            "docs": "https://www.drupal.org/docs/user_guide/en/index.html",
            "chat": "https://www.drupal.org/node/314178"
        },
        "repositories": [
            {
                "type": "composer",
                "url": "https://packages.drupal.org/8"
            }
        ],
        "require": {
            "composer/installers": "^1.2",
            "drupal/back_to_top": "^2.0",
            "drupal/core-composer-scaffold": "^9",
            "drupal/core-project-message": "^9",
            "drupal/core-recommended": "^9",
            "drupal/core-vendor-hardening": "^8.8"
        },
        "conflict": {
            "drupal/drupal": "*"
        },
        "minimum-stability": "dev",
        "prefer-stable": true,
        "config": {
            "sort-packages": true,
            "allow-plugins": {
                "composer/installers": true,
                "drupal/core-composer-scaffold": true,
                "drupal/core-project-message": true,
                "drupal/core-vendor-hardening": true,
                "dealerdirect/phpcodesniffer-composer-installer": true
            }
        },
        "extra": {
            "drupal-scaffold": {
                "locations": {
                    "web-root": "./"
                }
            },
            "installer-paths": {
                "core": [
                    "type:drupal-core"
                ],
                "libraries/{$name}": [
                    "type:drupal-library"
                ],
                "modules/contrib/{$name}": [
                    "type:drupal-module"
                ],
                "profiles/contrib/{$name}": [
                    "type:drupal-profile"
                ],
                "themes/contrib/{$name}": [
                    "type:drupal-theme"
                ],
                "drush/Commands/contrib/{$name}": [
                    "type:drupal-drush"
                ],
                "modules/custom/{$name}": [
                    "type:drupal-custom-module"
                ],
                "themes/custom/{$name}": [
                    "type:drupal-custom-theme"
                ]
            },
            "drupal-core-project-message": {
                "include-keys": [
                    "homepage",
                    "support"
                ],
                "post-create-project-cmd-message": [
                    "<bg=blue;fg=white>                                                         </>",
                    "<bg=blue;fg=white>  Congratulations, you’ve installed the Drupal codebase  </>",
                    "<bg=blue;fg=white>  from the drupal/legacy-project template!               </>",
                    "<bg=blue;fg=white>                                                         </>",
                    "",
                    "<bg=yellow;fg=black>Next steps</>:",
                    "  * Install the site: https://www.drupal.org/docs/8/install",
                    "  * Read the user guide: https://www.drupal.org/docs/user_guide/en/index.html",
                    "  * Get support: https://www.drupal.org/support",
                    "  * Get involved with the Drupal community:",
                    "      https://www.drupal.org/getting-involved",
                    "  * Remove the plugin that prints this message:",
                    "      composer remove drupal/core-project-message"
                ]
            }
        },
        "require-dev": {
            "drupal/core-dev": "^9",
            "drush/drush": "^11.0"
        }
    }
    
  3. No evidence of Ludwig
  4. Captcha Version: 8.x-1.2 | reCaptcha Version: 8.x-1.2
  5. Shared Hosting (Turbo CP at A2 Hosting)
  6. PHP 8.1 (also tested with PHP 7.4) both provide challenge but fail once submitted!
  7. https:/website.net/user/login (Currently set to Image Captcha)
    1. The website encountered an unexpected error. Please try again later.
      Error: Class 'ReCaptcha\ReCaptcha' not found in recaptcha_captcha_validation() (line 162 of modules/recaptcha/recaptcha.module).
      recaptcha_captcha_validation(, 'Google no captcha', Array, Object) (Line: 510)
      captcha_validate(Array, Object, Array)
      call_user_func_array('captcha_validate', Array) (Line: 282)
      Drupal\Core\Form\FormValidator->doValidateForm(Array, Object) (Line: 238)
      Drupal\Core\Form\FormValidator->doValidateForm(Array, Object, 'user_login_form') (Line: 118)
      Drupal\Core\Form\FormValidator->validateForm('user_login_form', Array, Object) (Line: 588)
      Drupal\Core\Form\FormBuilder->processForm('user_login_form', Array, Object) (Line: 320)
      Drupal\Core\Form\FormBuilder->buildForm(Object, Object) (Line: 73)
      Drupal\Core\Controller\FormController->getContentResult(Object, Object)
      call_user_func_array(Array, Array) (Line: 123)
      Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 564)
      Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 124)
      Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) (Line: 97)
      Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 158)
      Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 80)
      Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 58)
      Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 48)
      Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 106)
      Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 85)
      Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 48)
      Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 51)
      Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
      Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 708)
      Drupal\Core\DrupalKernel->handle(Object) (Line: 19)
  • Captcha Settings:

  • Captcha Settings

  • reCaptcha Settings:

  • reCaptcha

devad’s picture

Re: @bas123 #58.

Thank you for report.

4. Captcha Version: 8.x-1.2 | reCaptcha Version: 8.x-1.2

There is no such thing as reCaptcha Version: 8.x-1.2 among the reCaptcha releases.

reCaptcha branches: 8.x-1.x and 8.x-2.x are not supported any more.

You need to install reCaptcha version 8.x-3.0 with composer:

composer require 'drupal/recaptcha:^3.0'

after that, your composer.json file will also have this line:

    "require": {
        ...
        ...
        ...
        "drupal/recaptcha": "^3.0",
        ...
        ...
    },

and your "Class 'ReCaptcha\ReCaptcha' not found" error should be fixed.

Please, try and reply back the result.

caspervoogt’s picture

Composer-managed Drupal 9.3.3 here, and running into this with ReCaptcha 3.0 and 3.x-dev. Hosted, PHP 7.4. No Ludwig.

Composer.json:

{
    "name": "drupal-composer/drupal-project",
    "description": "Project template for Drupal 8 projects with composer",
    "type": "project",
    "license": "GPL-2.0-or-later",
    "authors": [
        {
            "name": "",
            "role": ""
        }
    ],
    "repositories": [
        {
            "type": "composer",
            "url": "https://packages.drupal.org/8"
        }
    ],
    "require": {
        "php": ">=7.0.8",
        "composer/installers": "^1.2",
        "cweagans/composer-patches": "^1.6.5",
        "drupal/admin_toolbar": "^3.0",
        "drupal/adminimal_admin_toolbar": "^1.11",
        "drupal/clientside_validation": "3.0.0-rc4",
        "drupal/config_pages": "^2.9",
        "drupal/console": "^1.0.2",
        "drupal/core-composer-scaffold": "^9.3",
        "drupal/core-recommended": "^9.3",
        "drupal/core-vendor-hardening": "^9.3",
        "drupal/field_group": "^3.2",
        "drupal/formdazzle": "^2.1",
        "drupal/marketo_ma": "^3.0@alpha",
        "drupal/paragraphs": "^1.12",
        "drupal/pathauto": "^1.8",
        "drupal/recaptcha": "^3.0",
        "drupal/svg_image": "^1.15",
        "drupal/upgrade_status": "^3.13",
        "drupal/webform": "^6.0",
        "drupal/webformnavigation": "^1.0@RC",
        "drush/drush": "^10.6",
        "vlucas/phpdotenv": "^4.0",
        "webflo/drupal-finder": "^1.0.0",
        "zaporylie/composer-drupal-optimizations": "^1.0"
    },
    "conflict": {
        "drupal/drupal": "*"
    },
    "minimum-stability": "dev",
    "prefer-stable": true,
    "config": {
        "sort-packages": true,
        "vendor-dir": "vendor",
        "allow-plugins": {
            "cweagans/composer-patches": true,
            "composer/installers": true,
            "drupal/core-composer-scaffold": true,
            "zaporylie/composer-drupal-optimizations": true,
            "drupal/console-extend-plugin": true,
            "drupal/core-vendor-hardening": true
        }
    },
    "autoload": {
        "classmap": [
            "scripts/composer/ScriptHandler.php"
        ],
        "files": ["load.environment.php"]
    },
    "scripts": {
        "pre-install-cmd": [
            "DrupalProject\\composer\\ScriptHandler::checkComposerVersion"
        ],
        "pre-update-cmd": [
            "DrupalProject\\composer\\ScriptHandler::checkComposerVersion"
        ],
        "post-install-cmd": [
            "DrupalProject\\composer\\ScriptHandler::createRequiredFiles"
        ],
        "post-update-cmd": [
            "DrupalProject\\composer\\ScriptHandler::createRequiredFiles"
        ]
    },
    "extra": {
        "composer-exit-on-patch-failure": true,
        "patchLevel": {
            "drupal/core": "-p2"
        },
        "drupal-scaffold": {
            "locations": {
                "web-root": "web/"
            }
        },
        "installer-paths": {
            "web/core": ["type:drupal-core"],
            "web/libraries/{$name}": ["type:drupal-library"],
            "web/modules/contrib/{$name}": ["type:drupal-module"],
            "web/profiles/contrib/{$name}": ["type:drupal-profile"],
            "web/themes/contrib/{$name}": ["type:drupal-theme"],
            "drush/Commands/contrib/{$name}": ["type:drupal-drush"]
        }
    }
}

Captcha version 1.2, ReCaptcha version 3.0 / 3.x-dev (tried both).

Error:

Error: Class 'ReCaptcha\ReCaptcha' not found in recaptcha_captcha_validation() (line 162 of /home/public_html/web/modules/contrib/recaptcha/recaptcha.module)
#0 /home/public_html/web/modules/contrib/captcha/captcha.module(510): recaptcha_captcha_validation()
#1 [internal function]: captcha_validate()
#2 /home/public_html/web/core/lib/Drupal/Core/Form/FormValidator.php(282): call_user_func_array()
#3 /home/public_html/web/core/lib/Drupal/Core/Form/FormValidator.php(238): Drupal\Core\Form\FormValidator->doValidateForm()
#4 /home/public_html/web/core/lib/Drupal/Core/Form/FormValidator.php(238): Drupal\Core\Form\FormValidator->doValidateForm()
#5 /home/public_html/web/core/lib/Drupal/Core/Form/FormValidator.php(238): Drupal\Core\Form\FormValidator->doValidateForm()
#6 /home/public_html/web/core/lib/Drupal/Core/Form/FormValidator.php(118): Drupal\Core\Form\FormValidator->doValidateForm()
#7 /home/public_html/web/core/lib/Drupal/Core/Form/FormBuilder.php(588): Drupal\Core\Form\FormValidator->validateForm()
#8 /home/public_html/web/core/lib/Drupal/Core/Form/FormBuilder.php(320): Drupal\Core\Form\FormBuilder->processForm()
#9 /home/public_html/web/core/lib/Drupal/Core/Entity/EntityFormBuilder.php(48): Drupal\Core\Form\FormBuilder->buildForm()
#10 /home/public_html/web/modules/contrib/webform/src/Entity/Webform.php(1233): Drupal\Core\Entity\EntityFormBuilder->getForm()
#11 /home/public_html/web/modules/contrib/webform/src/Controller/WebformEntityController.php(76): Drupal\webform\Entity\Webform->getSubmissionForm()
#12 [internal function]: Drupal\webform\Controller\WebformEntityController->addForm()
#13 /home/public_html/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(123): call_user_func_array()
#14 /home/public_html/web/core/lib/Drupal/Core/Render/Renderer.php(564): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
#15 /home/public_html/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(124): Drupal\Core\Render\Renderer->executeInRenderContext()
#16 /home/public_html/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(97): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext()
#17 /home/public_html/vendor/symfony/http-kernel/HttpKernel.php(158): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
#18 /home/public_html/vendor/symfony/http-kernel/HttpKernel.php(80): Symfony\Component\HttpKernel\HttpKernel->handleRaw()
#19 /home/public_html/web/core/lib/Drupal/Core/StackMiddleware/Session.php(58): Symfony\Component\HttpKernel\HttpKernel->handle()
#20 /home/public_html/web/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(48): Drupal\Core\StackMiddleware\Session->handle()
#21 /home/public_html/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(106): Drupal\Core\StackMiddleware\KernelPreHandle->handle()
#22 /home/public_html/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(85): Drupal\page_cache\StackMiddleware\PageCache->pass()
#23 /home/public_html/web/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(48): Drupal\page_cache\StackMiddleware\PageCache->handle()
#24 /home/public_html/web/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(51): Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle()
#25 /home/public_html/vendor/stack/builder/src/Stack/StackedHttpKernel.php(23): Drupal\Core\StackMiddleware\NegotiationMiddleware->handle()
#26 /home/public_html/web/core/lib/Drupal/Core/DrupalKernel.php(708): Stack\StackedHttpKernel->handle()
#27 /home/public_html/web/index.php(19): Drupal\Core\DrupalKernel->handle()
#28 {main}

User: Anonymous
Location: https://mysite.com/dlt-assessment?_wrapper_format=drupal_ajax&ajax_form=1
Referrer: https://mysite.com/dlt-assessment?page=public_sector_infrastructure
Severity: Error

devad’s picture

Category: Bug report » Support request
Priority: Critical » Normal

Re: #60

It is visible from your composer.json file that you do not have drupal/recaptcha module installed by composer.

You need to install reCaptcha version 8.x-3.0 with composer command:

composer require 'drupal/recaptcha:^3.0'

after that, your composer.json file will also have this line:

    "require": {
        ...
        ...
        ...
        "drupal/recaptcha": "^3.0",
        ...
        ...
    },

and your "Class 'ReCaptcha\ReCaptcha' not found" error should be fixed.

Please, try and reply back the result.

Changing the status of this issue to "Normal" & "Support Request" until somebody provides valid steps to reproduce the error with proper Composer installation.

caspervoogt’s picture

My mistake; I just pasted the wrong composer.json. I *was* using ReCaptcha but had switched to hCaptcha because ReCaptcha kept returning an Ajax error. The steps in my previous post still stand.

I am running Drupal 9.3.3. Here are my steps, which I just ran through once more just to make extra sure what I reported was correct:

  1. #composer require drupal/recaptcha (installs ReCaptcha 3.3)
  2. Enabled ReCaptcha, added ReCaptcha v2 keys
  3. Added captcha element to a form
  4. Tested form as anonymous user (since I have it set to not show for authenticated users). Still getting 'Class 'ReCaptcha\ReCaptcha' not found'.
  5. Cleared all caches, disabled CSS/JSS aggregation and site caching
  6. Re-tested form. Same error.
asdinnie’s picture

Hi

I am running Drupal 9.3.7 with reCAPTCHA 8.x-3.0.
Cannot use Composer as we are running our site on shared hosting. So reCAPTCHA was installed from within Drupal.

The reCAPTCHA worked fine until recently (I think!) until I did a minor upgrade to Drupal (from 9.3.4 to 9.3.7).

Now I get the error described above:
Error: Class 'ReCaptcha\ReCaptcha' not found in recaptcha_captcha_validation() (line 162 of /home/public_html/web/modules/contrib/recaptcha/recaptcha.module)

Is there an easy way around this problem now (given the plethora of fixes above) without using Composer?
I am not really a coder, more a site builder!

Many thanks,

God Bless

Andrew

devad’s picture

Re: #63

Is there an easy way around this problem without using Composer?

The solution (Ludwig patch) is here: #3152474: reCAPTCHA - Ludwig integration

asdinnie’s picture

Hi devad

Thanks for your reply.
Apologies for the delay in responding. I have been out of action...

Have installed Ludwig, added the json file and the reCAPTCHA now works a treat. Very pleased!
Have been getting spam with the basic captcha so this will make life easier for me as well.

Would like the option for "tick the box only" though. I get the "pick the right box" quiz each time when testing my forms.

Many thanks for your help and maintenance of Ludwig. Much appreciated.

One last question please:
I presume (?) I do my various module updates as per normal when required, or do I need to check Ludwig as well?

Many thanks again.

God Bless

Andrew

devad’s picture

Many thanks for your help and maintenance of Ludwig. Much appreciated.

Thanks. Welcome.

One last question please:
I presume (?) I do my various module updates as per normal when required, or do I need to check Ludwig as well?

Here is the guide you should follow during the updates:

Maintenance of Ludwig managed modules

ahmed.raza’s picture

Still getting the same error after installing the update v8.x-3.0

devad’s picture

Re: $67.

Please post the following data for debug purpose:

  1. Please confirm that you are using Composer to manage your site.
  2. Please, post the content of your composer.json file.
  3. Please ensure that the require section of your composer.json file have this line of code: "drupal/recaptcha": "^3.0",. If it doesn't have it - please read post #61 above.
  4. Please confirm that you are not using Ludwig module and that you have Ludwig module uninstalled if you have used it previously.
  5. Post the complete log error including User, Location, Referrer and Message
  6. The screenshots of your "CAPTCHA settings", "Form settings" and "reCAPTCHA" settings can help as well. You can hide the recaptcha keys at your screenshot of course.
bas123’s picture

devad,

Thank you for the specific correction!

I had reported the incorrect installation of reCaptcha (in #58 above) in my last post, as it was in fact Version: 8.x-3.0, however as it was indeed not registered as required in the composer.json, it must have been maintained and updated via the UI from it's original installation.

As the Developers of the theme (More Than Themes) the site is based on, who released it several years ago under Drupal 8 seemed to be slow in adopting Composer run installations. I had moved it entirely when I updated the site to Drupal 9, but had always updated modules in the UI when Drupal reported new versions.

Anyway, I added it via 'composer require', and the error is resolved!

Now I must wonder which other add-on modules I have running that might encounter this sort of issue going forward.
May I ask if there is anyway to sniff the potential for this sort of problems in advance short of adding each and every added module into the composer.json as a required dependency?

Thanks!

devad’s picture

Re: #69

Thank you for the specific correction!

You are welcome @bas123

May I ask if there is anyway to sniff the potential for this sort of problems in advance short of adding each and every added module into the composer.json as a required dependency?

I am not aware of such sniff tool. You can continue to manage all modules without library dependencies with UI of course. But it is best to add all your modules with composer. It is very easy to add them all. And if any of these modules will add some library dependency in its future release you will be safe since composer will recognize and include the new dependency automatically.

devad’s picture

Re: #60, #62

@caspervoogt Can you try to reproduce the same error on clean D9 installation and reply back if the error is still there?

mfh’s picture

I have the same issue in Drupal 9.4.1:

Error: Class "ReCaptcha\ReCaptcha" not found in recaptcha_captcha_validation() (line 162 of /home/users4/r/www/mysite/modules/recaptcha/recaptcha.module)
#0 /home/users4/r/www/mysite/modules/captcha/captcha.module(525): recaptcha_captcha_validation(false, 'Google no captc...', Array, Object(Drupal\Core\Form\FormState))
#1 [internal function]: captcha_validate(Array, Object(Drupal\Core\Form\FormState), Array)
#2 /home/users4/r/www/mysite/core/lib/Drupal/Core/Form/FormValidator.php(282): call_user_func_array('captcha_validat...', Array)
...

I can't use composer nor drush because my hosting plan provides only FTP and MySQLadmin, but no CLI access.

joshuautley’s picture

#5 > Method 2 (and I had to delete the old module dir which was outside the contrib dir - because new installs are configured within the composer.json file to install into contrib).

devad’s picture

Re: #72

I can't use composer nor drush because my hosting plan provides only FTP and MySQLadmin, but no CLI access.

You can build and maintain your site locally with Composer and upload it via FTP.

Or you can try D8/9/10 alternative to Composer - Ludwig. #3152474: reCAPTCHA - Ludwig integration

Metztli’s picture

Came across error subject when I upgraded recaptcha to 8.x-3.1 in Drupal 9.4.8.

I try to avoid tools, i.e., drush, etc., as I manually had been updating modules and Drupal itself since version 6.x.y; accordingly I had not used composer --until now. Composer fixed the error of the thread topic; nothing else worked.

dalpasso’s picture

StatusFileSize
new7.38 KB

Variation of #5 and #24 worked for me with D9.5.10, recaptcha 8.x-3.2:

Added these lines to recaptcha.module after the last use statement:

require_once dirname(__FILE__) . '/src/ReCaptcha/ReCaptcha.php';
require_once dirname(__FILE__) . '/src/ReCaptcha/RequestMethod.php';
require_once dirname(__FILE__) . '/src/ReCaptcha/RequestParameters.php';
require_once dirname(__FILE__) . '/src/ReCaptcha/Response.php';

Copied these class files from version: v8.x-3.1 of the module into recaptcha/src/ReCaptcha/

lubwn’s picture

Solution from #61 worked for me. Installing with composer command solved the issue:

composer require 'drupal/recaptcha:^3.0'

I have older Drupal 8.9.x website where update would be problematic so I installed recaptcha at first by hand, but came across this error.

I duplicated composer.json file somewhere locally, run the command, copied vendor directory to live website and it started to work.

dianacastillo’s picture

the solution in #76 worked for me , added the google directory into vendor directory and then added those lines to the recaptcha module as well as the files he includes in the zip to the src/recaptcha directory

idas’s picture

Same error for me with Drupal 10 and the latest version of this module.
You must necessarily install it with composer and work.

devad’s picture

Status: Active » Closed (outdated)

RE: #79

The Ludwig integration is added recently, so the latest 8.x-3.x-dev can be installed with Ludwig as well. The next 8.x-3.3 release will be Ludwig friendly as well.

Of course, please note that the Composer is highly recommended whenever possible!

I believe this issue can be closed as outdated. If you have a proper Composer installation (or the proper Ludwig + reCAPTHA 8.x-3.x-dev installation) and you experience this issue still - please feel free to reopen.

asdinnie’s picture

Hi

The error in forms has now reappeared when a non-authorised user submits a form.

Just upgraded to ReCaptcha 8.x-3.4 under Drupal 10.3.2
Running Ludwig 2.0.7 & CAPTCHA 8.x-1.15

I am still installing modules via Drupal...
Will have to upgrade to Composer sometime but it's a major pain as it's a shared server (home directory cannot be changed, etc.).

The following error whenever a form is submitted:
Error: Interface "ReCaptcha\RequestMethod" not found in include() (line 13 of /home/progres1/public_html/modules/recaptcha/src/ReCaptcha/RequestMethod/Drupal8Post.php).

The original lines in ludwig.json are present:

{
  "require": {
    "google/recaptcha": {
      "version": "v1.2.4",
      "url": "https://github.com/google/recaptcha/archive/1.2.4.zip"
    }
  }
}

Ludwig Packages tells me that google/recaptcha is downloaded.

Have I missed something?

Many thanks,
Andrew

alex oliver perez’s picture

Solution in #76 worked for me with Drupal core 10.3.2 and reCAPTCHA 8.x-3.4

asdinnie’s picture

Hi Alex

Thanks very for the note.
It now works!

Pity it doesn't stay like that after each upgrade...

Much appreciated,

Andrew

devad’s picture

Re: #81+

The patch #2 in the newly added related issue should fix issue described in comment #81. Please test and reply.