News:

Looking for documentation? Take a look on our wiki

Main Menu

Is captcha feature working ?

Started by Tataye, February 04, 2026, 16:13:44 PM

Previous topic - Next topic

Tataye

hello,

I migrate a site in j5.4.2 and last vm
Captcha when registering had some issues, and I disabled google recaptcha form the site. I have tested other captchas, and now it works in joomla but when i activate the captcha feature in virtuemart I have a field above the captcha containing : dynamic_recaptcha_1
and it does not work.
how can I have a working captcha during vm registration ?

Thanks

jflash

I also updated the site from J3 to J5.4.2 and didn't find any Captcha plugin that works :(

Tataye

Thanks for answering.
nobody else have found a solution ?

PRO

Joomla 5 does not have captcha native.
I had to download a plugin or something, I dont remember exactly,


rdcustom

solved the problem, now any captcha can work also on J5 and J6

components/com_virtuemart/hellpers/shopfunctionsf.php

line 1276: replace both renderCaptcha and checkCaptcha functions with this:

   /*
    * @author Davide Reitano
    */

   static public function renderCaptcha($config = 'reg_captcha', $id = 'dynamic_recaptcha_1') {

   static $counter;
   if (empty($counter)) $counter = 1;

   if ($id === 'dynamic_recaptcha_1') {
      $id = 'dynamic_recaptcha_' . $counter;
      $counter++;
   }

   if (VmConfig::get($config) and ((JFactory::getUser()->guest == 1) || (VmConfig::get($config . '_logged')))) {

      $captchaPlugin = JFactory::getConfig()->get('captcha', '');

      if ($captchaPlugin === '0') {
         $captchaPlugin = null;
      }

      JPluginHelper::importPlugin('captcha', $captchaPlugin);

      try {
         $pluginName = empty($captchaPlugin) ? '' : $captchaPlugin;

         // solo gruppo captcha, non evento globale Joomla
         vDispatcher::directTrigger('captcha', $pluginName, 'onInit', array($id));

         // nome campo STRINGA, non null
         $fieldName = 'cf-turnstile-response';

         $output = vDispatcher::directTrigger(
            'captcha',
            $pluginName,
            'onDisplay',
            array($fieldName, $id, 'required')
         );

      } catch (Exception $e) {
         JFactory::getApplication()->enqueueMessage($e->getMessage(), 'error');
         if (empty($output)) $output = array();
      }

      $out = '';

      if (is_array($output)) {
         foreach ($output as $html) {
            if (empty($html)) continue;
            $out .= $html;
         }
      } else if (is_string($output)) {
         $out .= $output;
      }

      return $out;
   }

   return '';
}

   /**
    * Check the Joomla ReCaptcha Plg
    *
    * @author Davide Reitano
    */
    static function checkCaptcha($config = 'reg_captcha') {

   if (VmConfig::get($config) and ((JFactory::getUser()->guest == 1) || (VmConfig::get($config . '_logged')))) {

      $app   = JFactory::getApplication();
      $input = $app->input;

      $captchaPlugin = JFactory::getConfig()->get('captcha', '');
      if ($captchaPlugin === '0') {
         $captchaPlugin = null;
      }

      $captchaResponse = $input->post->getString('cf-turnstile-response', '');

      if ($captchaResponse === '') {
         $captchaResponse = $input->post->getString('g-recaptcha-response', '');
      }

      if ($captchaResponse === '') {
         $captchaResponse = $input->post->getString('recaptcha_response_field', '');
      }

      if ($captchaResponse === '') {
         vmInfo('COM_VM_RECAPTCHA_ERROR');
         return false;
      }

      JPluginHelper::importPlugin('captcha', $captchaPlugin);

      try {
         $pluginName = empty($captchaPlugin) ? '' : $captchaPlugin;

         $res = vDispatcher::directTrigger(
            'captcha',
            $pluginName,
            'onCheckAnswer',
            array($captchaResponse)
         );
      }
      catch (Exception $e) {
         $errmsg = $e->getMessage();

         switch ($errmsg) {
            case 'missing-input-secret':
            case 'invalid-input-secret':
            case 'missing-input-response':
            case 'invalid-input-response':
            case 'bad-request':
            case 'timeout-or-duplicate':
               vmInfo('COM_VM_RECAPTCHA_ERROR_' . strtoupper(str_replace('-', '_', $errmsg)));
               break;
            default:
               vmInfo($errmsg);
               break;
         }

         return false;
      }

      if (empty($res)) {
         vmInfo('COM_VM_RECAPTCHA_ERROR');
         return false;
      }

      foreach ($res as $ret) {
         if (!$ret) {
            vmInfo('COM_VM_RECAPTCHA_ERROR');
            return false;
         }
      }

      return true;
   }

   return true;
}