如何在Joomla!组件扩展中添加验证码captcha
在Joomla!验证码使用了bigoCaptha插件,这个插件本地下载地址:http://www.maycode.com/index.php/docman/doc_details/102-joomla-.html 下载后安装插件,并激活(似乎不激活也没问题)。 接下来来我们修改自己的组件程序: 1、controller.php的修改,在controller.php中加入 function displaycaptcha() { global $mainframe; $Ok = null; $mainframe->triggerEvent('onCaptcha_Display', array($Ok)); if (!$Ok) { echo "<br/>Error displaying Captcha<br/>"; } } function _checkCaptcha() { global $mainframe; $return = false; $word = JRequest::getVar('word', false, '', 'CMD'); $mainframe->triggerEvent('onCaptcha_confirm', array($word, &$return)); if ($return) { return true; } else return false; } 第一段程序用来显示验证码,你可以在任何需要的地方: <img src="/index.php?option=com_**&task=displaycaptcha" /><input name="work" type=text>这样就能够显示验证码了 第二段程序是用来验证是否验证码输入正确的私有函数。 2、在视图模板文件中,添加验证码显示和输入的代码:
<img src="/index.php?option=com_**&task=displaycaptcha" /><input name="work" type=text> 其实也不完全局限在组件的视图模板文件中,在插件,模块等需要的地方,都可以添加。 3、修改验证部分,这部分程序应该是POST后的处理程序,通常可能是controller.php的save函数,反正就是对应的task,添加如下代码: if (!$this->_checkCaptcha()) { JError::raiseError("403","You have entered the wrong CAPTCHA sequence. Please try again."); return false; } 整个验证码的添加过程完成了。
转自maycode.com
|