Search code examples
phpzend-frameworkzend-formzend-decorators

How do I set the text of an element within a Zend_Form decorator


I am trying to set the text inside the lengend tag within the following code:

    $element->setDecorators(array(
        'ViewHelper',
        'Description',
        'Errors',
        array(array('legend' => 'HtmlTag'), array('tag' => 'legend', 'placement' => 'prepend')),
        array(array('fieldset' => 'HtmlTag'), array('tag' => 'fieldset')),
    ));

The following is generated:

    <fieldset>
    <legend></legend>
    </fieldset>

and I would like:

    <fieldset>
    <legend>Blah</legend>
    </fieldset>

Any help would be appreciated!

Update:

Using Regis's answer, I implemented this like so:

    $decorator = new Zend_Form_Decorator_Fieldset();
    $decorator->setLegend("legend");

    $element->setDecorators(array(
        'ViewHelper',
        'Description',
        'Errors',
        array($decorator),
        array(array('div' => 'HtmlTag'), array('tag' => 'div')),
    ));        

Solution

  • you can try in this different way:

    $decorator = new Zend_Form_Decorator_Fieldset();
    $decorator->setLegend("legend");        
    $element->addDecorators(array($decorator));