1

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?

Roderik
  • 401
  • 1
  • 7
  • 14

2 Answers2

2

In newer versions of Zend you can add the tagClass parameter. See below in the "Label" array

$username->setAttrib("class", "text_field")
     ->setDecorators(array(
               'ViewHelper',
               'Description',
               'Errors',
               array(array('data'=>'HtmlTag'),array('tag' => 'div', 'class' => 'right')),
               array('Label', array('tag' => 'div', 'tagClass' => 'left', 'class' => 'label right')),
               array(array('row'=>'HtmlTag'),array('tag'=>'div', 'class' => 'group wat-cf'))
        ));
Andre
  • 2,449
  • 25
  • 24
0

This is pretty common question. I think, that this answer may by helpful in this case too:

Add some html to Zend Forms

Take look at Padraic's tutorial as well.

Community
  • 1
  • 1
takeshin
  • 49,108
  • 32
  • 120
  • 164