Search code examples
phpzend-frameworkzend-formzend-decoratorstwitter-bootstrap

Zend_Form: Using HtmlTag Decorator twice?


Is it possible to wrap the form element in a div AND the whole block (label, element, errors etc) in another div using the HtmlTag decorator? I'd like to use Twitter's Bootstrap with Zend_Form like so:

<div class="clearfix">
  <label for="xlInput">X-Large Input</label>
  <div class="input">
    <input class="xlarge" id="xlInput" name="xlInput" size="30" type="text" />
  </div>
</div>

Any ideas?


Solution

  • Try this (untested):

    $element->setDecorators( array(
        'Errors',
        'ViewHelper',
        array( array( 'wrapperField' => 'HtmlTag' ), array( 'tag' => 'div', 'class' => 'input' ) ),
        array( 'Label', array( 'placement' => 'prepend' ) ),
        array( array( 'wrapperAll' => 'HtmlTag' ), array( 'tag' => 'div', 'class' => 'clearfix' ) ),
    ) );
    

    edit: Label was wrong; adjusted.