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:
/**
* Classe d'extension de Zend_Form_Element_Captcha
*
* Corrige un bug par rapport au décorateur du captcha.
*
*/
class App_Form_Element_Captcha extends Zend_Form_Element_Captcha {
public function render(Zend_View_Interface $view = null)
{
$captcha = $this->getCaptcha();
$captcha->setName($this->getFullyQualifiedName());
$decorators = $this->getDecorators();
$decorator = $captcha->getDecorator();
if (!empty($decorator)) {
array_unshift($decorators, $decorator);
}
$decorator = array('Captcha', array('captcha' => $captcha));
array_unshift($decorators, $decorator);
$this->setDecorators($decorators);
$this->setValue($this->getCaptcha()->generate());
return ''.parent::render($view).'';
}
}
Et son utilisation pour modifier le décorateur:
$captcha->setDecorators(array(
array('decorator' => array('td' => 'HtmlTag'), 'options' => array('tag' => 'td')),
array('Label', array('tag' => 'td'))
));
Aucun commentaire