I found this example code in one of the bug reports ...
(http://framework.zend.com/issues/browse/ZF-4045)
Works good enough to get an idea of how to put the captcha to use. (as there
is limited documentation examples)
I didn't see one of these Zend_Form_Element_Captcha in your code, maybe it
is what you need.
Slightly modified for quick test...
Try something like this :
// (fix pathing for your dev setup)
// setup for captcha image
$captchaImage = new Zend_Captcha_Image();
$captchaImage->setFont(DATAPATH.'/VeraBd.ttf');
$captchaImage->setFontSize(30);
$captchaImage->setWordlen(6);
$captchaImage->setImgDir(CAPTCHAPATH);
$captchaImage->setImgUrl('/images/captcha/');
$captchaImage->setWidth(175);
$captchaImage->setHeight(75);
$captchaImage->setName('captcha');
// text box for user input
$elementCaptcha = new Zend_Form_Element_Captcha(
'captcha', array('captcha' => $captchaImage)
);
// make form
$form = new Zend_Form(array(
'action' => '/manage/',
'method' => 'post',
));
// add items to form
$form->addElement($elementCaptcha, 'captcha')
->addElement('submit', 'process', array(
'required' => false,
'ignore' => true,
'label' => 'Process',
));
// set image to view
$this->view->captcha = $captchaImage;
// check if form post
$request = $this->getRequest();
if (!$request->isPost()) {
// if not show form
$this->view->form = $form;
}
// test form valid?
if (!$form->isValid($request->getPost())) {
// if not show form
$this->view->form = $form;
}
// this was originally in the view script
// but I didn't want to wack my existing so
// modified it to work here
// if we have form, show it - or form did validate
if (isset($this->view->form)) {
echo '<h2>Testing Captcha</h2>';
echo $this->view->form;
} else {
echo '<h2>Captcha Form validated!</h2>';
}
// dump the capcha data
if (isset($this->view->captcha)) {
echo '<h4>Captcha word dump</h4>';
echo '<pre>'.
var_dump($this->view->captcha->getWord()).'</pre>';
}
-----Original Message-----
From: dele454 [mailto:[EMAIL PROTECTED]
Sent: Tuesday, November 04, 2008 5:19 AM
To: [email protected]
Subject: Re: [fw-general] Zend_Capcha
Any one out there with help? Please!!
dele454 wrote:
>
> hi,
>
> i am trying to verify the text submitted to match that of the captcha.
> If
> valid(same) echo 'validated'.
>
> class JoinController extends Zend_Controller_Action {
>
> public function indexAction(){
>
> $this->_helper->layout->setLayout('layout-site');
> $view = new Zend_View();
> // Originating request:
> $captcha = new Zend_Captcha_Image(array(
> 'name' => 'foo',
> 'height' => 100,
> 'width' => 202,
> 'wordLen'=> '6',
> 'expiration' => '300',
> 'font' =>
> 'C:/xampp/htdocs/xampp/mainevent/public_html/img/font/ravie.ttf',
>
'imgDir'=>'C:/xampp/htdocs/xampp/mainevent/public_html/img/captcha',
> 'imgUrl' => '../img/captcha',
> 'fontSize' => '24',
>
>
>
> ));
> $id = $captcha->generate();
> $this->view->showCaptcha = $captcha->render($view);
>
>
>
> if ($captcha->isValid($_POST['captcha'])) {
> echo "Validated!";
>
> }
> else{ echo "no";
> print_r($captcha->getMessages());}
> }
>
>
>
> }
>
> When i submit the form it always echos 'no'!. Printing the error
> message i get this
>
> Array ( [missingValue] => Empty captcha value )
>
> How can i sort this out. I am thinking the captcha will always have a
> different value on post when compared to the text field. How can i
> resolve this.
>
-----
dee
--
View this message in context:
http://www.nabble.com/Zend_Capcha-tp20300142p20319514.html
Sent from the Zend Framework mailing list archive at Nabble.com.