Error during validation
joepsyko opened this issue · comments
The captcha validation doesn't work.
Here's the problem:
Undefined index: 03AI-r6f77YzXhrhogFOkkbXXUmowiWZcyk-USxgmpyg9s1ubtnkkLlQNQw53h7fYh_amPjOtAm4rLXbxk5vPGLn_Qgl-v_in0zI33ciI9DV6OmXHY5U-qJcwi0vA-fjTBly7QabRnwTzV4nSuYtzkL1YkULzS0wY06SBpBk0Qd5UaTDDNJxvvm6TCkzfySdzyx8a5fj6laAMJe45Hz7i3KjGs5PzNDW4vLlHpNWvmKiSN7KciKwrICLY9TgRyP8Bf-pwDqg2TL2v98VZNm6iofV0OXRCRDJZlWO72cbJPXIO5QyNnlLOKmDi3blsMt2sWMmA-ZmRBu88T
public function isValid($value, $context = null)
{
if (empty($value) && ! is_array($context)) {
$this->error(self::MISSING_VALUE);
return false;
}
$service = $this->getService();
$res = $service->verify($context[$value]);
if (! $res) {
$this->error(self::ERR_CAPTCHA);
return false;
}
if (! $res->isValid()) {
$this->error(self::BAD_CAPTCHA);
return false;
}
return true;
}
$res = $service->verify($context[$value]);
$value is the token, not the key.
Can anyone please help me to fix this problem?
Thanks
Can you provide the rest of the code ?
$reCaptcha = new \Zend\Captcha\ReCaptcha(['site_key' => $this->config['recaptcha']['publicKey'], 'secret_key' => $this->config['recaptcha']['privateKey']]);
$this->add([
'name' => 'g-recaptcha-response',
'type' => \Zend\Form\Element\Captcha::class,
'options' => [
'captcha' => $reCaptcha,
],
]);
Can you apply this patch to your zend-form please?
Sure, but you have to explain me how, I never did this before.
If you're using composer, the easiest way is to create a new branch and then edit your composer.json:
add:
"repositories": [
{
"type": "git",
"url": "https://github.com/akrabat/zend-form"
}
],
above the "require": {
line.
Then change your zendframework/zend-form
requirement to:
"zendframework/zend-form": "dev-recaptcha2 as 2.10.x-dev",
You should then be able to do a composer update zendframework/zend-form
to get the change.
I have the following error:
Problem 1
- zendframework/zendframework 3.0.0 requires zendframework/zend-form ^2.9 -> satisfiable by zendframework/zend-form[2.10.x-dev, 2.9.x-dev].
- zendframework/zendframework 3.0.0 requires zendframework/zend-form ^2.9 -> satisfiable by zendframework/zend-form[2.10.x-dev, 2.9.x-dev].
- zendframework/zendframework 3.0.0 requires zendframework/zend-form ^2.9 -> satisfiable by zendframework/zend-form[2.10.x-dev, 2.9.x-dev].
- Can only install one of: zendframework/zend-form[2.10.x-dev, dev-recaptcha2].
- Can only install one of: zendframework/zend-form[2.9.x-dev, dev-recaptcha2].
- Can only install one of: zendframework/zend-form[dev-recaptcha2, 2.10.x-dev].
- Can only install one of: zendframework/zend-form[dev-recaptcha2, 2.9.x-dev].
- Installation request for zendframework/zend-form dev-recaptcha2 -> satisfiable by zendframework/zend-form[dev-recaptcha2].
- Installation request for zendframework/zendframework (locked at 3.0.0) -> satisfiable by zendframework/zendframework[3.0.0].
Okay. I'll try and reproduce here.
I've worked out what's happening now. I didn't expect the name of the Captcha element to be "g-recaptcha-response".
Expect a fix shortly!
ok but if I change the name of the element I have a different error:
Illegal offset type
/vagrant/vendor/zendframework/zend-captcha/src/ReCaptcha.php:264
$value now is an array:
Array
(
[recaptcha_challenge_field] =>
[recaptcha_response_field] =>
)
Yes. Zend-Form's view helper needs to know about the new zend-captcha which is what zendframework/zend-form#139 does.
The instructions above to test it were slightly wrong.
You need
"zendframework/zend-form": "dev-recaptcha2 as 2.10.x-dev",
in your composer json
and then you should be able to do composer update zendframework/zend-form
to get the updated zend-form component that allows a different element name.
Fix for using 'g-recaptcha-response' as the element name needs an update to zend-captcha that I'm currently working on.
Now I have problem with the constraint of composer.
I have these in my composer.json:
"minimum-stability": "dev",
"prefer-stable": true,
Problem 1
- The requested package zendframework/zend-form dev-recaptcha2 as 2.10.x-dev exists as zendframework/zend-form[2.0.3, 2.0.4, 2.0.5, 2.0.6, 2.0.7, 2.0.8, 2.1.0, 2.1.1, 2.1.2, 2.1.3, 2.1.4, 2.1.5, 2.1.6, 2.2.0, 2.2.0rc1, 2.2.0rc2, 2.2.0rc3, 2.2.1, 2.2.10, 2.2.2, 2.2.3, 2.2.4, 2.2.5, 2.2.6, 2.2.7, 2.2.8, 2.2.9, 2.3.0, 2.3.1, 2.3.2, 2.3.3, 2.3.4, 2.3.5, 2.3.6, 2.3.7, 2.3.8, 2.3.9, 2.4.0, 2.4.0rc1, 2.4.0rc2, 2.4.0rc3, 2.4.0rc4, 2.4.0rc5, 2.4.0rc6, 2.4.0rc7, 2.4.1, 2.4.10, 2.4.11, 2.4.2, 2.4.3, 2.4.4, 2.4.5, 2.4.6, 2.4.7, 2.4.8, 2.4.9, 2.5.0, 2.5.1, 2.5.2, 2.5.3, 2.6.0, 2.7.0, 2.7.1, 2.8.0, 2.8.1, 2.8.2, 2.8.3, 2.8.4, 2.9.0, 2.9.1, 2.9.2, dev-develop, 2.10.x-dev, dev-legacy, dev-master, 2.9.x-dev] but these are rejected by your constraint.
You still have the:
"repositories": [
{
"type": "git",
"url": "https://github.com/akrabat/zend-form"
}
],
section?
This is the composer.json what worked for me: https://gist.github.com/a62ceda184cc0ceddedfd28a8fc3c25a
No I removed that line
Ok now works.
Now my question is: when I can remove your fork and use the official zend-form repository?
"soon"
Soon? :D
days, weeks. months?
Ok thank you for your support!
@joepsyko Released version 2.7.2 of zend-captcha, so your original use of g-recaptcha-response
as the name of your element should now work.
Thanks, the latest version is 2.7.1, not 2.7.2.