sept
18
2009

Correction Element Captcha

Pour ce début de week-end, je vais vous faire partager une correction de Zend_FormElement_Captcha pour la mise en forme avec un tableau (via les décorateurs).

Je redéfinis juste la fonction render() de Zend_Form_Element_Captcha. Voici donc la correction apportée:

 

 PHP |  copy code |? 
01
/**
02
 * Classe d'extension de Zend_Form_Element_Captcha
03
 * 
04
 * Corrige un bug par rapport au décorateur du captcha.
05
 *
06
 */
07
class App_Form_Element_Captcha extends Zend_Form_Element_Captcha {
08
 
09
    public function render(Zend_View_Interface $view = null)
10
    {
11
        $captcha    = $this->getCaptcha();
12
        $captcha->setName($this->getFullyQualifiedName());
13
 
14
        $decorators = $this->getDecorators();
15
 
16
        $decorator  = $captcha->getDecorator();
17
        if (!empty($decorator)) {
18
            array_unshift($decorators, $decorator);
19
        }
20
 
21
        $decorator = array('Captcha', array('captcha' => $captcha));
22
        array_unshift($decorators, $decorator);
23
 
24
        $this->setDecorators($decorators);
25
 
26
        $this->setValue($this->getCaptcha()->generate());
27
 
28
     return ''.parent::render($view).'';
29
    }
30
}

Et son utilisation pour modifier le décorateur:
 PHP |  copy code |? 
1
$captcha->setDecorators(array(
2
            array('decorator' => array('td' => 'HtmlTag'), 'options' => array('tag' => 'td')),
3
            array('Label', array('tag' => 'td'))
4
        )); 

Articles Connexes

A propos de l'Auteur: Benjamin Besse

Je suis Analyste Développeur chez Goomeo et je suis passioné par tout ce qui touche aux technologies du Web. J'ai commencé par apprendre l'utilisation du Framework Zend et j'ai continué naturellement via Android. Le tout seulement avec les bases acquises en DUT et Licence professionnelle Informatique.

Laisser un commentaire

Mots-Clefs