Issues

ZF-11257: setIsArray does not work with decorators

Description

Everything is in the title. Zend_Form->setIsArray does not work with decorators.


        $screen_name = $this->createElement('text','screen_name')
                ->addFilter('stringTrim')
                ->addFilter('stripTags')
                ->setIsArray(true);

result is :


        $screen_name = $this->createElement('text','screen_name')
                ->addFilter('stringTrim')
                ->addFilter('stripTags')
                ->setDecorators(array('Col'))
                ->setIsArray(true);

result is :

the [] disappears...

Comments

The standard decorators from Zend_Form doesn't include a decorator with the name "Col". Please publish your decorator.


<?php
class Lovonair_Form_Decorator_Col extends Zend_Form_Decorator_Abstract  implements Zend_Form_Decorator_Marker_File_Interface  
{
    public function buildLabel()
    {
        $element = $this->getElement();
        $label = $element->getLabel();
        if ($translator = $element->getTranslator()) {
            $label = $translator->translate($label);
        }
        if ($element->isRequired()) {
            $label .= '*';
        }
        $label .= '';
        $messages = $element->getMessages();   
        if (empty($messages)){
             return $element->getView()
                       ->formLabel($element->getName(), $label);
        }else{
             return $element->getView()
                       ->formLabel($element->getName(), $label, array('class'=>'error'));
        }
    }

    public function buildInput()
    {
        $element = $this->getElement();
        $helper  = $element->helper;
                   
            return $element->getView()->$helper(
                $element->getName(),
                $element->getValue(),
                $element->getAttribs(),
                $element->options
            );
        
    }

    public function buildErrors()
    {
        $element  = $this->getElement();
        $messages = $element->getMessages();        
        if (empty($messages)) {
            return '';
        }
        $return = '';     
           
        foreach($messages as $mess){
         $return .= '

' . $mess . '

'; } return $return; } public function buildDescription() { $element = $this->getElement(); $desc = $element->getDescription(); if (empty($desc)) { return ''; } return '

' . $desc . '

'; } public function render($content) { $element = $this->getElement(); if (!$element instanceof Zend_Form_Element) { return $content; } if (null === $element->getView()) { return $content; } $separator = $this->getSeparator(); $placement = $this->getPlacement(); $label = $this->buildLabel(); $input = $this->buildInput(); $errors = $this->buildErrors(); $desc = $this->buildDescription(); if(!empty($errors)) $errorClass = " formRed"; else $errorClass = ""; if(!empty($this->_options) && isset($this->_options['class'])) $class = ' '.$this->_options['class']; else $class=''; if(!empty($this->_options) && isset($this->_options['id'])) $id = ' id="'.$this->_options['id'].'"'; else $id=''; if(!empty($this->_options) && isset($this->_options['style'])) $style = ' style="'.$this->_options['style'].'"'; else $style=''; if($element instanceof Zend_Form_Element_MultiCheckbox){ $inputr = '
'; $inputr .= $input; $inputr .= '
'; $input = $inputr; } if($element instanceof Zend_Form_Element_Submit || $element instanceof Zend_Form_Element_Button){ $output = '
' . ' ' . $input . '' . '
'; }elseif($element instanceof Zend_Form_Element_Checkbox && (isset($this->_options['type']) && $this->_options['type']=='term')){ $output = '
' . '

' . ''.$input.' '.$element->getLabel().'' . '

' . $errors . '
' . '
'; }else{ $output = '
' . '

'.$label.'

' . '

'.$input.'

' . $desc . $errors . '
' . '
'; } switch($placement) { case (self::PREPEND): return $output . $separator . $content; case (self::APPEND): default: return $content . $separator . $output; } } }

This is a bug in your decorator and not in the framework!

Please check the default decorators:


class Zend_Form_Decorator_ViewHelper extends Zend_Form_Decorator_Abstract
{
    // …

    public function render($content)
    {
        // …
        
        $name = $element->getFullyQualifiedName();
        
        // …
    }
}

Or look a the API-Doc: [http://framework.zend.com/apidoc/core/…]

For a error in the documentation open a new issue. Thanks.

[http://framework.zend.com/manual/en/…]