Hello
Create recapctha with help PHP in VIEw:
$captcha = JCaptcha::getInstance('recaptcha', array('namespace' => 'captcha_keystring_rent_request' ));
echo $captcha->display('recaptcha', 'recaptcha', 'required');
Check recapctha result in controller, with help PHP:
$captcha = JCaptcha::getInstance('recaptcha', array('namespace' => 'captcha_keystring_rent_request'));
if($captcha){
$answer = $captcha->checkAnswer('captcha_keystring_rent_request'); <-- there exception: Google return "invalid-input-response"
if(!$answer) {
//show error, "bad filled captcha"
exit();
}
}
Until Joomla 3.9.15, this code work good (include Joomla 3.9.14)
Now we receive exception from Google.
Joomla 3.9.15.
reproduce on many PC, keys in recaptcha plugin are good.
In Joomla registration recaptcha works good
Please check attachment
Regards
Andrew!
screen shot 2020-03-02 at 19 43 09
Priority | Critical | ⇒ | Medium |
what captcha plugin is enabled?
recaptcha
should work
however recaptcha_invisible
has a bug in plugin implementation, the plugin ignores $code
at all
joomla-cms/plugins/captcha/recaptcha_invisible/recaptcha_invisible.php
Lines 128 to 138 in 35f1325
It's Recaptcha. Since #26882 it makes use of $code
argument. It seems correct to me as well, but causes issues when passing whatever to checkAnswer()
like in this case.
If we keep it as, @akbet1, you'll have to solve it on your end by removing erroneous argument or by passing the actual answer, e.g.
$answer = $captcha->checkAnswer();
Hi
@Fedik
If I check joomla-cms/plugins/captcha/recaptcha_invisible/recaptcha_invisible.php
in joomla 3.9.15
I see there code exactly as you propose use
But we use "recaptcha", we not use "recaptcha_invisible"
@SharkyKZ
we use
$captcha = JCaptcha::getInstance('recaptcha', array('namespace' => 'captcha_keystring_rent_request'));
$answer = $captcha->checkAnswer('captcha_keystring_rent_request');
"captcha_keystring_rent_request" - it need because we have 2 forms on page, so we need check which captcha user press.
If I try use:
$answer = $captcha->checkAnswer();
I see next error:
Too few arguments to function Joomla\CMS\Captcha\Captcha::checkAnswer(), 0 passed in /home/windsorh/public_html/components/com_realestatemanager/realestatemanager.php on line 945 and exactly 1 expected
File: /home/windsorh/public_html/libraries/src/Captcha/Captcha.php
Line: 177
Regards
okay, then what exactly is 'captcha_keystring_rent_request', and how you get it?
As I believe (before), it is namespace, we use it at time show captcha:
$captcha = JCaptcha::getInstance('recaptcha', array('namespace' => 'captcha_keystring_rent_request' ));
echo $captcha->display('recaptcha', 'recaptcha', 'required');
so on 1 page we may have 2 captha, as example for show second captcha we use:
$captcha = JCaptcha::getInstance('recaptcha', array('namespace' => 'captcha_keystring_review' ));
echo $captcha->display('recaptcha', 'recaptcha', 'required');
'captcha_keystring_review' - another namespace
Regards
It's supposed to be the answer.
joomla-cms/libraries/src/Captcha/Captcha.php
Lines 170 to 177 in 35f1325
'captcha_keystring_review' - another namespace
that incorrect,
$captcha->checkAnswer($code);
the $code
supposed to be a token, answer from recpatcha api on client side
Thank you!
but will be best if you provide "how to", and not only hints, some like:
show captcha:
$captcha = JCaptcha::getInstance('recaptcha', array('namespace' => 'captcha_keystring_rent_request' ));
echo $captcha->display('recaptcha', 'recaptcha', 'required');
check captcha:
//Check enabled plugin captcha-recaptcha
$recaptchaPluginEnabled = JPluginHelper::isEnabled('captcha', 'recaptcha');
//Check enable option captcha-recaptcha in admin form
$app = JFactory::getConfig();
$recaptchaAdminEnabled = false;
if($app->get('captcha') == 'recaptcha'){
$recaptchaAdminEnabled = true;
}
if( $googleRecaptchaEnabled && $recaptchaPluginEnabled ){
$captcha = JCaptcha::getInstance('recaptcha', array('namespace' => 'captcha_keystring_buy_request'));
if($captcha){
$get_answer = JFactory::getApplication()->input->get("g-recaptcha-response", "");
$answer = $captcha->checkAnswer($get_answer);
//check captcha
if(!$answer ) {
//captcha check error
exit();
}
}
}
Regards
if( $googleRecaptchaEnabled && $recaptchaPluginEnabled ){
need replace to
if( $recaptchaPluginEnabled && $recaptchaAdminEnabled ){
but !!!!!!
How this worked in joomla 3.9.14 and before ?!!!
without:
$get_answer = JFactory::getApplication()->input->get("g-recaptcha-response", "");
Regards
@akbet1 @SharkyKZ has already provided the answer above #28191 (comment):
It's Recaptcha. Since #26882 it makes use of $code argument. It seems correct to me as well, but causes issues when passing whatever to checkAnswer() like in this case.
PR #26882 was merged end of December last year, this explains that there is a difference between 3.9.14 and 3.9.15.
Hi
But continue this not good, as me seem, you may give possibility run
$answer = $captcha->checkAnswer(); <-- without argumenets
and in plugin, if call with "$code = null", you need add code like below:
public function onCheckAnswer($code = null)
{
$input = \JFactory::getApplication()->input;
$privatekey = $this->params->get('private_key');
if( $code == null) $code = $input->get("g-recaptcha-response", "");
Regards
But, Thank you for your support !!!
There is already code like that in Recaptcha plugin:
If code is not provided, g-recaptcha-response
input variable is used.
Sorry,
Bur As I wrote:
If I try use:
$answer = $captcha->checkAnswer();
I see next error:
Too few arguments to function Joomla\CMS\Captcha\Captcha::checkAnswer(), 0 passed in /home/windsorh/public_html/components/com_realestatemanager/realestatemanager.php on line 945 and exactly 1 expected
File: /home/windsorh/public_html/libraries/src/Captcha/Captcha.php
Line: 177
Regards
You're right. It can't be omitted. So it should be either the answer or null
.
Status | New | ⇒ | Closed |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2022-11-16 09:00:19 |
Closed_By | ⇒ | joomdonation | |
Labels |
Added:
No Code Attached Yet
Removed: ? |
reset priority according to our published guides
This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/28191.