1
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='' /> ". $this->loadImage();
$rule = htmlspecialchars(XOOPS_CAPTCHA_REFRESH, ENT_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 .= " <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($rule, ENT_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