1
TheFinni
Captcha attempts left change with js
  • 2008/4/21 17:18

  • TheFinni

  • Just popping in

  • Posts: 75

  • Since: 2003/11/25


I was using the Captcha feature in one of my modules and noticed that the "Maximum attempts" didn't correspond to the actual attempts left after clicking the refresh image.

Here's what I did to fix it. Perhaps someone else would like to change this in their code. Small fix but more informative to the user.

In xoops_root/Frameworks/captcha/image.php

I edited the following functions as following:

function render()
    {
        
$form "<input type='text' name='".$this->config["name"]."' id='".$this->config["name"]."' size='" $this->config["num_chars"] . "' maxlength='" $this->config["num_chars"] . "' value='' /> &nbsp; "$this->loadImage();
        
$rule htmlspecialchars(XOOPS_CAPTCHA_REFRESHENT_QUOTES);
        if(
$this->config["maxattempt"]) {
            
//TN changed: $rule .=  " | ". sprintf( constant("XOOPS_CAPTCHA_MAXATTEMPTS"), $this->config["maxattempt"] );
            
$rule .=  " | "constant("XOOPS_CAPTCHA_MAXATTEMPTS"). ' <span id="captcha_attempts">'.$this->config["maxattempt"].'</span>';
        }
        
$form .= "&nbsp;&nbsp;<small>{$rule}</small>";
        
        return 
$form;
    }


    function 
loadImage()
    {
        
$rule $this->config["casesensitive"] ? constant("XOOPS_CAPTCHA_RULE_CASESENSITIVE") : constant("XOOPS_CAPTCHA_RULE_CASEINSENSITIVE");
        
//TN edited: $ret = "<img id='captcha' src='" . XOOPS_URL. "/". $this->config["imageurl"]. "' onclick="this.src='" . XOOPS_URL. "/". $this->config["imageurl"]. "?refresh='+Math.random()"."" align='absmiddle'  style='cursor: pointer;' alt='".htmlspecialchars($rule, ENT_QUOTES)."' />";
        //TN added javascript to change attempts numbers:
        
$ret '';
        
$ret .= '<script type="text/javascript">function changeAttemptsN(){
        var captchaNholder = document.getElementById("captcha_attempts");
        var capthcaN = captchaNholder.childNodes[0].nodeValue;
        var newcaptchaN = capthcaN - 1;
        captchaNholder.childNodes[0].nodeValue = newcaptchaN;
         }</script>'
;
        
$ret .= "<img id='captcha' src='" XOOPS_URL"/"$this->config["imageurl"]. "' onclick="this.src='" . XOOPS_URL. "/". $this->config["imageurl"]. "?refresh='+Math.random()".";changeAttemptsN()" align='absmiddle'  style='cursor: pointer;' alt='".htmlspecialchars($ruleENT_QUOTES)."' />";
        return 
$ret;
    }


You will also need to change the language definition file:

xoops_root/Frameworks/captcha/language/english.php (or whichever language)

to:

define("XOOPS_CAPTCHA_MAXATTEMPTS""Maximum attempts:");//TN Used to be Maximum attempts: %d

Login

Who's Online

151 user(s) are online (99 user(s) are browsing Support Forums)


Members: 0


Guests: 151


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