Issues

ZF-10804: Zend_Form_Decorator_Captcha render duplication issues

Issue Type: Bug Created: 2010-12-09T13:09:33.000+0000 Last Updated: 2011-01-24T05:53:58.000+0000 Status: Resolved Fix version(s): Reporter: Franz de Leon (kelmadics) Assignee: Guy Halford-Thompson (guyht) Tags: - Zend_Form

Related issues: - ZF-9338

Attachments:

Description

I am not sure if this is a bug or just misunderstanding of the functionality. In summary I basically want to add a wrapper or a break in the html of the captcha like this (notice the

&
):

<img alt="" height="50" src="/images/captcha/92a1b8fec46aab102a83838af42f3124.png" width="140"></img>

<br></br>I am using this to create the element:

<pre class="highlight">
    $captcha = new Zend_Form_Element_Captcha('Captcha', array(
          'label' => 'Captcha Label',
          'captcha' => 'Image',
          'captchaOptions' => array(
            'captcha' => 'Image',
            'width' => 140,
            'height' => 50,
            'wordLen' => 5,
            'fontSize' => 25,
            'font' => APPLICATION_PATH . '/../public/fonts/BRLNSDB.TTF',
            'imgDir' => APPLICATION_PATH . '/../public/images/captcha',
            'imgUrl' => '/images/captcha/'
          )
        ));
        $captcha->addPrefixPath('My_Form_Decorator', 'My/Form/Decorator/', 'decorator');
        $this->addElement($captcha);

This can be accomplished by creating a Custom Decorator and overwriting the Captcha Decorator something like below :

<pre class="highlight">
class My_Form_Decorator_Captcha extends Zend_Form_Decorator_Abstract
{   
   public function render($content)
    {
        $element = $this->getElement();
        $view    = $element->getView();
        $placement = $this->getPlacement();
        $separator = $this->getSeparator();
        $captcha = $element->getCaptcha();

        $markup  = '

' . $captcha->render($view, $element) . '

 <br></br>';
        switch ($placement) {
            case 'PREPEND':
                $content = $markup . $separator .  $content;
                break;
            case 'APPEND':
            default:
                $content = $content . $separator . $markup;
        }
        return $content;
    } 
}

Hopefully there would be an easier way to do a simple thing like this but the problem I cant figure out is is if you DO NOT want to overwrite the captcha say calling it something like: My_Form_Decorator_CustomCaptchaStyle instead of My_Form_Decorator_Captcha

Recreating my element below:

<pre class="highlight">
    $captcha = new Zend_Form_Element_Captcha('Captcha', array(
          'label' => 'Captcha Label',
          'captcha' => 'Image',
          'captchaOptions' => array(
            'captcha' => 'Image',
            'width' => 140,
            'height' => 50,
            'wordLen' => 5,
            'fontSize' => 25,
            'font' => APPLICATION_PATH . '/../public/fonts/BRLNSDB.TTF',
            'imgDir' => APPLICATION_PATH . '/../public/images/captcha',
            'imgUrl' => '/images/captcha/'
          )
        ));
        $captcha->addPrefixPath('My_Form_Decorator', 'My/Form/Decorator/', 'decorator');
                $captcha->setDecorators(array(
            'CustomCaptchaStyle',
            array('HtmlTag', array('tag' => 'dd')),
            'Label'
        ));
     $this->addElement($captcha);

THE PROBLEM is there is no way of deleting or stopping the Zend_Form_Decorator_Captcha from being rendered which always results to 2 captcha images being displayed like the code below:

<pre class="highlight">

<img alt="" height="50" src="/images/captcha/90c02ee2485d98b5ce11b397c0a89871.png" width="140"></img>

<img alt="" height="50" src="/images/captcha/90c02ee2485d98b5ce11b397c0a89871.png" width="140"></img>

<br></br>Ive also tried $captcha->removeDecorator('Captcha') to no avail;

Comments

Posted by Guy Halford-Thompson (guyht) on 2011-01-24T05:32:41.000+0000

I think that the reason for this is that by default Zend_Form_Captcha will add Zend_Form_Decorator_Captcha and so you are basically rendering it twice because both Zend_Form_Decorator_Captcha and My_Form_Decorator_Captcha are being called.

This is not actually a bug so I will mark it as closed, you might have more success querying the mailing list if you are still having issues (form decorators can be a real pain sometimes).

Posted by Kai Uwe (kaiuwe) on 2011-01-24T05:46:08.000+0000

Look also here: ZF-8094

Have you found an issue?

See the Overview section for more details.

Copyright

© 2006-2016 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.

Contacts