This implements a very hard-core implementation of a captcha, without use of any controllers or views. Of course it's discouraged to code like that, but if you have your deadline, this is the last resort you can use:
$sec_image_field = $f->addField('line', 'sec_image', 'Security code')
->setNotNull()
->setNoSave();
$captcha_src = '/lib/kcaptcha/?' . $session_name . '=' . session_id();
$kaptcha_img = $sec_image_field->getTag('img',array('src' => $captcha_src, 'id' => 'kpt' ));
$kaptcha_img .= ' <a href="#" onclick="d=new Date(); (jQuery(\'#kpt\')'.
'.attr(\'src\', \'' . $captcha_src . '&t=\' + d.getTime()));return false;">';
$kaptcha_img .= '<i class="atk-icon atk-icons-nobg atk-icon-arrows-left3"></i>';
$kaptcha_img .= ' reload</a>';
$sec_image_field->template->set('after_field', '<ins>Enther the code you see below</ins> <span>' . $kaptcha_img . '</span>'
Note: you'll need to download and install kcapcha into /lib/kcapcha/ from their website.
Example: http://agiletech.ie/contact
ReCapcha implementation you have found is much more decent, but not Ideal. It manually looks into the POST data and simply sets flag telling you if it was typed properly or not. Here is example usage:
$rc = $form->add('View_ReCaptcha');
....
if($form->isSubmitted()){
...
if(!$rc->isValid()){
$js=$this->js->univ();
if($r->getError()){
$js->alert($rc->getError());
}else{
$js->alert('Error in capcha');
}
$js->execute();
}
....
}
Note: You would need recapcha lib installed. See source.
Making better Capcha
Probably the best way would be to introduce a new field type, (Form_Field_Capcha) which does the whole thing completely automatically. It shouldn't bundle any PHP libraries but would rely on 3rd party service for image generation. It also must use the standard form validation.