Index: branches/RC/core/units/general/helpers/captcha_helper.php =================================================================== diff -u -N -r8929 -r10539 --- branches/RC/core/units/general/helpers/captcha_helper.php (.../captcha_helper.php) (revision 8929) +++ branches/RC/core/units/general/helpers/captcha_helper.php (.../captcha_helper.php) (revision 10539) @@ -109,4 +109,55 @@ return false; } + /** + * Generates captcha code for showing on form + * + * @param kEvent $event + */ + function prepareCode(&$event) + { + if ($this->Application->IsAdmin() || $this->Application->RecallVar($event->getPrefixSpecial() . '_captcha_code')) { + // when code found don't generate it 2nd time + return ; + } + + $this->Application->StoreVar($event->getPrefixSpecial() . '_captcha_code', $this->GenerateCaptchaCode()); + } + + /** + * Validates captcha code on form + * + * @param kEvent $event + * @param bool $check_request + * @return bool + */ + function validateCode(&$event, $check_request = true) + { + if ($this->Application->IsAdmin()) { + // no captcha codes in admin + return true; + } + + if ($check_request) { + // perform validation only when field is found on form + list ($id, $field_values) = each($this->Application->GetVar($event->getPrefixSpecial())); + if (!array_key_exists('Captcha', $field_values)) { + // when captcha code not submitted + return true; + } + } + + $object =& $event->getObject(); + /* @var $object kDBItem */ + + if ($object->GetDBField('Captcha') != $this->Application->RecallVar($event->getPrefixSpecial() . '_captcha_code')) { + $object->SetError('Captcha', 'captcha_error', 'lu_captcha_error'); + + $this->Application->StoreVar($event->getPrefixSpecial() . '_captcha_code', $this->GenerateCaptchaCode()); + return false; + } + + return true; + } + } \ No newline at end of file