Open kujain opened 3 years ago
OK - with some hacking I was able to get the helper working in this way: Controller:
$this->loadComponent('Recaptcha.Recaptcha');
$this->viewBuilder()->addHelper('Recaptcha.Recaptcha');
.....
if ($this->request->is('post')) {
if ($this->Recaptcha->verify()) {
View:
<?= $this->Recaptcha->display(); ?>
Now I see this error on submitting:
Call to a member function getData() on null
Error
| public function verify()
| {
| $controller = $this->_registry->getController();
| $gRecaptchaResponse = $controller->request->getData("g-recaptcha-response");
| if (!empty($gRecaptchaResponse)) {
|
| $resp = $this->recaptcha->verifyResponse(
| new Client(),
There are also a number of warnings showing up like:
Deprecated (16384): notEmpty() is deprecated. Use notEmptyString(), notEmptyArray(), notEmptyFile(), notEmptyDate(), notEmptyTime() or notEmptyDateTime() instead. - //vendor/cakephp-fr/recaptcha/src/Validation/ConfigValidator.php, line: 29
You can disable all deprecation warnings by setting `Error.errorLevel` to `E_ALL & ~E_USER_DEPRECATED`, or add `vendor/cakephp-fr/recaptcha/src/Validation/ConfigValidator.php` to `Error.ignoredDeprecationPaths` in your `config/app.php` to mute deprecations from only this file. [CORE/src/Core/functions.php, line 316]
Deprecated (16384): `Validator::errors()` is deprecated. Use `Validator::validate()` instead. - /vendor/cakephp-fr/recaptcha/config/bootstrap.php, line: 20
You can disable all deprecation warnings by setting `Error.errorLevel` to `E_ALL & ~E_USER_DEPRECATED`, or add `vendor/cakephp-fr/recaptcha/config/bootstrap.php` to `Error.ignoredDeprecationPaths` in your `config/app.php` to mute deprecations from only this file. [CORE/src/Core/functions.php, line 316]
Notice (1024): Undefined property: AgenciesController::$request in //vendor/cakephp-fr/recaptcha/src/Controller/Component/RecaptchaComponent.php on line 87 [CORE/src/Controller/Controller.php, line 321]
Thanks!
I managed to make this work with a few edits to the core code as below:
RecaptchaComponent.php: change line 14
use Cake\Http\Client;
change line :
$gRecaptchaResponse = $controller->getRequest()->getData("g-recaptcha-response");
Recaptcha.php: change line 87:
use Cake\Http\Client;
Could you please review and update if this fix is valid? Thanks very much!
Seems like this issue was fixed at this pull request: https://github.com/cakephp-fr/recaptcha/pull/13
And there's also an opened pull request to fix the deprecation errors for Validator::errors() here: https://github.com/cakephp-fr/recaptcha/pull/18
Not sure If cake17 is active
I don't think the documentation is accurate for 4.1. I get errors with:
if I add manually (
$this->addPlugin('Recaptcha');
), I get the following error on loading the form:Please help!