Contents |
Using Captcha from PHP (module, UDT, etc)
Creating a reference to the Captcha module object
From a module:
$captcha =& $this->getModuleInstance('Captcha'); if ($captcha) { // The Captcha module is installed }
Otherwise:
global $gCms; if (isset($gCms->modules['Captcha'])) { $captcha =& $gCms->modules['Captcha']['object']; }
Getting the Captcha
$captcha->getCaptcha();
for example:
echo $captcha->getCaptcha();
or:
$smarty->assign('captcha', $captcha->getCaptcha());
Checking the user input
$captcha->checkCaptcha($user_input);
Should be passed the user input as variable, returns TRUE if it is correct, FALSE otherwise
For example:
if ($captcha->checkCaptcha($params['captcha_input']) == TRUE) { // input is correct }
or:
if ($captcha->checkCaptcha($_POST['captcha_input'])) { //input is correct }
Using Captcha from your content/templates
Use $gCms->modules.Captcha.object->getCaptcha() to display the Captcha.
$gCms->modules.Captcha.object->checkCaptcha() can be used to validate the user input.
{if isset($smarty.post.captcha_input)} {if $gCms->modules.Captcha.object->CheckCaptcha($smarty.post.captcha_input) == TRUE} {* Content protected by Captcha *} You are human {else} You seem to be a computer {/if} {/if} <form action="?page={$page_alias}" method="post"> <p> {$gCms->modules.Captcha.object->GetCaptcha()} <input name="captcha_input" type="text" /> <br /> <input type="submit" /> </p> </form>