Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Zend Framework - Zend_Form Decorator Issue

I have a class that extends Zend_Form like this (simplified):

class Core_Form extends Zend_Form
{
    protected static $_elementDecorators = array(
        'ViewHelper',
        'Errors',
        array('Label'),
        array('HtmlTag', array('tag' => 'li')),
    );  

    public function loadDefaultDecorators()
    {
        $this->setElementDecorators(self::$_elementDecorators);
    }
}

I then use that class to create all of my forms:

class ExampleForm extends Core_Form
{
    public function init()
    {
        // Example Field
        $example = new Zend_Form_Element_Hidden('example');
        $this->addElement($example);
    }
}

In one of my views, I have a need to display only this one field (without anything else generated by Zend_Form). So in my view I have this:

<?php echo $this->exampleForm->example; ?>

This works fine, except for it generates the field like this:

<li><input type="hidden" name="example" value=""></li>

This is obviously because I set the element decorators to include HtmlTag: tag => 'li'.

My question is: How can I disable all decorators for this element. I don't need decorators for hidden input elements.

like image 397
leek Avatar asked Dec 17 '22 09:12

leek


1 Answers

the best place to set it is public function loadDefaultDecorators()

for example like this:

class ExampleForm extends Core_Form
    {
        public function init()
        {
            //Example Field
            $example = new Zend_Form_Element_Hidden('example');
            $this->addElement($example);
        }

        public function loadDefaultDecorators()
        {
            $this->example->setDecorators(array('ViewHelper'));
        }
    }
like image 85
Martin Rázus Avatar answered Jan 01 '23 18:01

Martin Rázus