« Return to Thread: My_Captcha_Image

Re: My_Captcha_Image

by zendlearner :: Rate this Message:

Reply to Author | View in Thread

Hi Lucas,

Thanks for your response. Unfortunately, neither 'captcha' => $captchaimage nor 'captcha' => 'My_Captcha_Image' works.  You seem to be on the right track, but I get an exception:

Warning: Exception caught by form: Image CAPTCHA requires font Stack Trace: #0 C:\wamp\www\takefoodout\library\TakeFoodOut\Captcha\Image.php(423): TakeFoodOut_Captcha_Image->_generateImage('c60e6c7b5c85f79...', 'r7v5b7wa') #1 C:\wamp\www\takefoodout\library\Zend\Form\Element\Captcha.php(149): TakeFoodOut_Captcha_Image->generate() #2 C:\wamp\www\takefoodout\library\Zend\Form\Decorator\FormElements.php(100): Zend_Form_Element_Captcha->render() #3 C:\wamp\www\takefoodout\library\Zend\Form.php(2595):
...

Here is my code:
<?php
class TakeFoodOut_SignupForm extends Zend_Form
{
    public function init()
    {
        $this->setMethod('post');

        // add elements
       
        $this->addElement('captcha', 'captcha', array(
        'label' => 'Word Verification',
        'description' => 'Please verify that you are human',
        'helper' => null,
        'order'  => 4,
          'captcha' => array(
        'captcha' => 'Image',
        'wordLen' => 6,
        'timeout' => 300,
        'font' => 'pics/captcha/DeJaVuSansMono.ttf',
        'fontSize' => 30,
        'imgDir' => 'pics/captcha/img',
        'imgUrl' => 'http://takefoodout/pics/captcha/img'
                         )
                ));
               
                $this->getElement('captcha')
                        ->addPrefixPath('TakeFoodOut_Captcha', 'TakeFoodOut/Captcha/', 'captcha')
                        ->setCaptcha(new TakeFoodOut_Captcha_Image());


Lucas Corbeaux wrote:
I'm not a Zend form experienced user, and I can't answer you totally...
But after looking Zend_Form_Element_Captcha::setCaptcha() method, I
think something like that :

$captchaimage = new My_Captcha_Image();

        $this->addElement('captcha', 'captcha', array(
        'label' => 'Word Verification',
        'description' => 'Please verify that you are human',
        'helper' => null,
        'order' => 4,
          'captcha' => $captchaimage
        ));



Would works, because setCaptcha accept both Zend_Captcha_Adapter
instance and options array.
I can also be totally wrong, but maybe try to give to the 'captcha'
index the value 'My_Captcha_Image' instead of 'Image', if you want your
element to instanciate it.

Hope one of this answer will help...
Lucas

zendlearner a écrit :
> Hi, I am having the same problem and I don't know how to use
> My/Captcha/Image.php instead of Zend/Captcha/Image.php when I create form
> element using new Zend_Form_Element_Captcha.
>
> $captchaimage = new My_Captcha_Image();
>
>         $this->addElement('captcha', 'captcha', array(
>         'label' => 'Word Verification',
>         'description' => 'Please verify that you are human',
>         'helper' => null,
>         'order' => 4,
>           'captcha' => array(
>         'captcha' => 'Image',
>         'wordLen' => 6,
>         'timeout' => 300,
>         'font' => 'pics/captcha/DeJaVuSansMono.ttf',
>         'fontSize' => 30,
>         'imgDir' => 'pics/captcha/img',
>         'imgUrl' => 'http://foo/pics/captcha/img'
> )
> ));
>
>
>
>
> Raavi Raaj wrote:
>  
>> Hi,
>>
>> I would like to extend the Image adapter for the Captcha element.
>> I have done so and placed it in My/Captcha/Image.php
>>
>> *My question...*
>> I have no clue how to use my adapter for the captcha.
>>
>> *This is how I define and add the element*
>> $captcha = new Zend_Form_Element_Captcha('captcha', array('captcha' =>
>> array('captcha' => 'Image', 'wordLen' => 4)));
>> $this->addElement($captcha);
>>
>> All help is appreciated.
>>
>> -R
>>
>> P.S.
>> - I have a canventional setup
>> - All my forms extend My_Form
>>
>>
>>    
>
>  

 « Return to Thread: My_Captcha_Image