Here is what SPForm uses (modified somewhat):
spfCaptchaTpl Tpl chunk:
<div class="spf_captcha_instructions">[[+spf-captcha-instructions]]</div>
<div class="spf_captcha_image">[[+spf-captcha-image]]</div>
<div class="spf_input_pair">
<span class="spf_block_prompt">[[+spf-captcha-input-prompt]]</span>
<span class="spf_normal_input">[[+spf-captcha-input]]</span>
</div>
Snippet code:
/* make sure we can find the captcha files */
if (! file_exists($this->modx->getOption('assets_path'). "components/captcha/captcha.php")) {
echo '
' . $this->modx->lexicon('no-captcha');
exit();
}
$useMathString = $this->modx->getOption('useMathString',$this->spfconfig,true);
if ($useMathString) {
$alt = $this->modx->lexicon("login_mathstring_message");
} else {
$alt = $this->modx->lexicon("login_captcha_message");
}
if ($useMathString) {
$_SESSION['captcha.use_mathstring'] = 'true';
$captcha_prompt = $this->modx->lexicon("login_mathstring_message");
$captcha_input_prompt = $this->modx->lexicon("captcha_mathstring_code").":";
} else {
$_SESSION['captcha.use_mathstring'] = 'false';
$captcha_prompt = $this->modx->lexicon("login_captcha_message");
$captcha_input_prompt = $this->modx->lexicon("captcha_code") . ":";
}
$captcha_image= '<img '. 'onclick="this.src=' . "'" . $this->modx->getOption('assets_url') . "components/captcha/captcha.php?rand='" .
"+Math.floor(Math.random()*200);".'"' .' src="'. $this->modx->getOption('assets_url') . 'components/captcha/captcha.php?rand='.rand().'" alt="'.$alt.'" />';
$this->placeholders['spf-captcha-instructions'] = $captcha_prompt;
$this->placeholders['spf-captcha-image'] = $captcha_image;
$this->placeholders['spf-captcha-input-prompt'] = $captcha_input_prompt;
$this->placeholders['spf-captcha-input'] = '<input type="text" name="verify" value="" />';
$spfCaptchaTpl = $this->modx->getOption('spfcaptchaTpl',$this->spfconfig,'spfcaptchaTpl');
$this->placeholders['spf-captcha-stuff'] = $this->modx->getChunk($spfCaptchaTpl);
return $this->modx->getChunk($spfCaptchaTpl, $this->placeholders);
Basic Verification code (assumes that the name of your Captcha input field is 'verify'):
if($_SESSION['veriword'] != $_POST['verify']) {
/* failure */
if ($MyDebug)) {
echo "Session: " . $_SESSION['veriword'] . '
';
echo "Post: " . $_POST['verify'] . '
';
}
} else {
/* success */
}
Note that you can turn the mathstring option on with this in the snippet tag:
Also, this code is inside a class, so you'll have to get rid of $this-> if you're not using it inside a class.
------------------------------------------------------------------------------------------
PLEASE, PLEASE specify the version of MODX you are using.
MODX info for everyone:
http://bobsguides.com/modx.html
[ed. note: BobRay last edited this post 14 years, 1 month ago.]