views:

112

answers:

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?

A: 

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

http://stackoverflow.com/questions/2566432/add-some-html-to-zend-forms/2567305#2567305

Take look at Padraic's tutorial as well.

takeshin