After a lot of struggle, I've figured out how to implement the standard Joomla reCaptcha.

But now my problem is the verifying of it on the server side.

The steps of the reCaptcha:

  1. I have a form with the recaptcha implemented like this (works fine):

    $captcha_plugin = JFactory::getConfig()->get('captcha');
    if ($captcha_plugin != '0') {
        $captcha = JCaptcha::getInstance($captcha_plugin);
        $field_id = 'captcha';
        print $captcha->display($field_id, $field_id, 'g-recaptcha');
  2. On submit I send an AJAX call to this url (works fine):

    'index.php?option=com_content&format=ajax&view=article&task=loginUser&tmpl=component' It's a file I've made inside com_content > views > article

  3. The code in my loginUser task / function (not validating, see end of question)

    public function _logInUser( $form ){
        $captcha_plugin = JFactory::getConfig()->get('captcha');
        $captcha = JCaptcha::getInstance($captcha_plugin);
        $completed = $captcha->CheckAnswer($form[2]['value']);
        echo $form[2]['value'];

Update: I've also tried like this, still gives me false when it should return true:

$dispatcher = JEventDispatcher::getInstance();
$res = $dispatcher->trigger('onCheckAnswer',$form[2]['value']);
    die('Invalid Captcha');

echo $form[2]['value']; returns "" when captcha is not clicked and returns something like this when clicked: "03AMGVjXgaSV3U5UnezVUIFslFElvrMDe2gOVoJtEwtT9SVMaqG47cyC16CPrl01H3yKVF1y4aaBOnK-E1AeBa1H8XoBE17fN-8L3j0_W5mvO8g9kbrVg-yYEuk1B9lSTWxYfn9kf23yPTY-wlIOijh04vqBwUTLFoiTL-Jw9Ae-l2uvgVrnb1qyBrYt5dtvfRWvwbAx6h6qGXh4WBZz19eFkTv5mTmheGsp4s-5e-VtiqMEQJynNxE0fjxqQxKNyCECAK6SRbtLdZ8NTlDAG4dOd4zfb-R2aIYxwvPOxLjxrlO_5xggTOwqA"

So it must be working.

but this line always returns false : $completed = $captcha->CheckAnswer($form[2]['value']);

and when removing $form[2]['value'] in $captcha->CheckAnswer

I get this output:

Warning: Missing argument 1 for Joomla\CMS\Captcha\Captcha::checkAnswer(), called in /customers/a/c/e/test-mysite.dk/httpd.www/test/components/com_content/views/article/view.ajax.php on line 35 and defined in /customers/a/c/e/test-mysite.dk/httpd.www/test/libraries/src/Captcha/Captcha.php on line 192 Notice: Undefined variable: code in /customers/a/c/e/test-mysite.dk/httpd.www/test/libraries/src/Captcha/Captcha.php on line 200

INFO UPDATE for future readers!: Joomla does NOT provide reCaptcha for the login form. Only for the registration and contact form. I've found it here: https://forum.joomla.org/viewtopic.php?t=910764

  • Any warnings or errors generated from JFactory::getConfig()->get('captcha') or JCaptcha::getInstance($captcha_plugin) or $captcha->CheckAnswer($form[2]['value'])? Have you got debugging turned all the way up? Commented Oct 18, 2018 at 8:13
  • Yes it's set to developer mode. I´ve added all the errors to my question Commented Oct 18, 2018 at 8:21
  • No, I mean with your originally posted attempt -- any warnings/error with that? Commented Oct 18, 2018 at 8:23
  • ahh!... no that gives me no errors, only the false output of CheckAnswer Commented Oct 18, 2018 at 8:25
  • 1
    Ah! actually it dosen't show up in the login page when I remove my override of the login page. No warnings though. I think I'll try to install a fresh Joomla on a subdomain and see if I can get it to work just as the normal reCaptcha :(... The only thing I can think off is that I have J2 store installed and that have a plugin for captcha(but the plugin is disabled, so should be that) Commented Oct 18, 2018 at 10:15

2 Answers 2


Fist of all, PHP is case sensitive. This means that CheckAnswer and checkAnswer is not the same (note the capital c).

The correct usage is $captcha->checkAnswer('your_captcha_id').
What's the problem with your approach:
You are passing the captcha's post result as the ID of your captcha.

Since you have used captcha as the $field_id when you included the captcha, you should write $captcha->checkAnswer('captcha') to check the answer.

  • hmmmm... Still gives me false but this really seem to be the right solution... The strange thing is that I can´t get the reCaptcha to work just as standard inplementation. I'll try to install a fresh Joomla now and see if I can get it to work... Thanks for your answer! I'll let you know what happens Commented Oct 19, 2018 at 12:23
  • Just found out that Joomla does not provide the captcha for the login form out of the box. I found it here: forum.joomla.org/viewtopic.php?t=910764 ....I will try to copy my files over to a new installation and see if your answer works! :) Commented Oct 19, 2018 at 15:09
  • I did a lot of testing and trying! I simply can't get it to work :( I managed to get the default Joomla captcha to work on registration and contact forms - so it is installed correctly. But testing my own implementation with your corrections, still gives me a bool(false) response Commented Oct 19, 2018 at 19:36
  • I've accepted this answer as I found out that if I moved the script to a custom plugin rater than inside com_content > views > article. Then your answer did work! Commented Oct 23, 2018 at 19:46
  • I'm glad it worked out after all @JonasB Commented Oct 24, 2018 at 13:12

Never got it to work with Joomla's $captcha->checkAnswer().

So instead, I've omitted Joomla's checking solution and went straight with Google's checking API.

Here's the code I'm successfully using for the checking part:

$secretKey = "my_secret_key";

$form[2]['value'] is the response from the reCaptcha

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.