Adding a class to the $tag surrounding a <label> in a Zend_Form with the Label decorator

Posted by Roderik on Stack Overflow See other posts from Stack Overflow or by Roderik
Published on 2010-05-08T18:02:38Z Indexed on 2010/05/08 18:08 UTC
Read the original article Hit count: 383

I'm trying to get the following html out of Zend_Form

<div class="group wat-cf">
  <div class="left">
    <label class="label right">Username</label>
  </div>
  <div class="right">
    <input type="text" class="text_field">
  </div>
</div>

Using the following code:

$username->setAttrib("class", "text_field")
         ->setDecorators(array(
                           'ViewHelper',
                               'Description',
                   'Errors',
                   array(array('data'=>'HtmlTag'), array('tag' => 'div', 'class' => 'right')),
                               array('Label', array('tag' => 'div', 'class' => 'label right')),
                               array(array('row'=>'HtmlTag'),array('tag'=>'div', 'class' => 'group wat-cf'))
            ));

I can get the next fragment

<div class="group wat-cf">
  <div id="username-label">
    <label for="username" class="label right required">Username:</label>
  </div>
  <div class="right">
    <input type="text" name="username" id="username" value="" class="text_field">
  </div>
</div>

so apart from some extra id's and required classes i don't mind, i need to get a class "left" on div id="username-label"

Now adding class to the Label line, gets the class added on the element. I also don't see and option to do this in the Label decorator code itself. So i need a custom Label decorator, or is there some other way i'm missing?

© Stack Overflow or respective owner

Related posts about zend-framework

Related posts about zend-form