1
tank1955
Captcha problem when multiple instances on page
  • 2009/10/24 15:57

  • tank1955

  • Module Developer

  • Posts: 276

  • Since: 2007/9/7 1


For next version of ShoutBox module I thought I would revisit the use of captcha images for anonymous posts. By rights the image id tag of the captcha image should be unique so there are no conflicts if another instance appears on the same page. For example, the person who reported this had defined the shoutbox block to appear in the Right column on All Pages. Therefore it would appear on the Registration page which also employs captcha. So now we have two instances of captcha but both images have the same id tag, which is the default one provided in the class config file.

I am working with 2.3.3 as I explore this issue. I thought it should be as simple as calling setConfig() but it appears not. Here is what my code looks like in the block.

include_once(XOOPS_ROOT_PATH.'/class/xoopsform/formcaptcha.php');
$shoutcaptcha = new XoopsFormCaptcha();
$result $shoutcaptcha->setConfig('name','shoutboxcaptcha');
$block['captcha_caption'] = $shoutcaptcha->getCaption();
$block['captcha_render'] = $shoutcaptcha->render();


Calling setConfig appears to have no affect on the config value. Am I overlooking something?

2
ghia
Re: Captcha problem when multiple instances on page
  • 2009/10/24 18:20

  • ghia

  • Community Support Member

  • Posts: 4953

  • Since: 2008/7/3 1


Is the name not to be added as second argument in the new XoopsFormCaptcha?
XoopsFormCaptcha($caption ''$name 'xoopscaptcha'$skipmember true$configs = array())

3
tank1955
Re: Captcha problem when multiple instances on page
  • 2009/10/25 13:30

  • tank1955

  • Module Developer

  • Posts: 276

  • Since: 2007/9/7 1


You are correct ghia. That is actually where I started. As I worked through how the class is supposed to work I eventually narrowed it down to the setConfig method that appears to be the problem.

The image.php file contains the code which renders the image and makes the tag assignment. Here is the specific code I am looking at:

function loadImage()
    {
        
$ret "<img id='" . ($this->config['name']) . "' src='" XOOPS_URL "/" $this->config["imageurl"] . "' onclick="this.src='" . XOOPS_URL . "/" . $this->config["imageurl"] . "?refresh='+Math.random()"."" style='cursor: pointer; vertical-align: middle;' alt='' />";
        return 
$ret;
    }


From what I have been able to figure out I believe that once the "name" value is assigned in the config array contained in the config.php it can not be changed. This is based on the following found in xoopscaptcha.php:

function setConfig($name$val)
    {
        if (isset(
$this->$name)) {
            
$this->$name $val;
        } else {
            
$this->config[$name] = $val;
        }
        
        return 
true;
    }


As soon as the config array is loaded $this->name is also assigned so performing the setConfig can reassign $this->name but not $this->config["name"].

4
tank1955
Re: Captcha problem when multiple instances on page
  • 2009/10/25 14:16

  • tank1955

  • Module Developer

  • Posts: 276

  • Since: 2007/9/7 1


Even though I figured out a hack to make the image id's unique the first image is still overwritten by the second image.

Login

Who's Online

182 user(s) are online (105 user(s) are browsing Support Forums)


Members: 0


Guests: 182


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Mar 31
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits