Thx, for fast reply!
This package, from what i see, is for version 2.4, and this configuration:
extensions: recaptcha: Contributte\ReCaptcha\DI\ReCaptchaExtension recaptcha: secretKey: *** siteKey: ***
I suppose, is for the full version of the framework? How can I use it for standalone forms? Where should I pass secretKey and siteKey?
Aha, I'm sorry, I've overlooked you are using standalone version. When you don't need integration for Nette framework, just use Google's PHP SDK: https://github.com/…le/recaptcha
The package mentioned above is just adapter of this Google's SDK for Nette. — update: ok, it isn't, but that does not change anything.
Last edited by dakur (2021-03-25 12:44)
- David Matějka
- Moderator | 6406
try something like this:
$provider = new \Contributte\ReCaptcha\ReCaptchaProvider($siteKey, $siteSecret); \Contributte\ReCaptcha\Forms\InvisibleReCaptchBinding::bind($provider); \Contributte\ReCaptcha\Forms\ReCaptchBinding::bind($provider); // and now you can call $form->addInvisibleRecaptcha('recaptcha'); // or $form->addRecaptcha('recaptcha');
you can also add a recaptcha component to the form directly without extension methods:
$provider = new \Contributte\ReCaptcha\ReCaptchaProvider($siteKey, $siteSecret); $form['recaptcha'] = new Contributte\ReCaptcha\Forms\RecaptchaField(); $form['recaptcha']->setRequried(true);
to avoid installing unnecessary nette/di dependency, you can use “replace” section in composer.json
Sorry I`m back :)
I have small problem displaying the error. In other fields, when I do
$form['other_field']->errors, I get array of
specific field errors, unfortunately in recapatcha case, this array is always
empty, but when i want display all errors on top of the form in this way
$form->errors then the error from recaptcha is in array.
Do you know why this is happening and how to get a single error from recapthca?