Currently I'm working with Zend and I've a tiny problem that I want to solve.
I've got a class that I want to add to each text type inputs, but instead of setting that class attrib I would like to add it from the custom form decorator, because it has to be on each text inputs and textarea and you know sometimes do something again and again is annoying.
I'm pretty new to Zend so I don't know how where should I start...
Heres the code of my decorators only for the text elements:
'Zend_Form_Element_Text' => array(
'ViewHelper',
'Errors',
array ('Description', array('tag' => 'td','class' =>'iconset', 'escape'=>false )),
array (array ('data' => 'HtmlTag'), array ('tag' => 'td', 'class' => 'element')),
array ('Label', array ('tag' => 'td')),
array (array ('row' => 'HtmlTag'), array ('tag' => 'tr'))
),
With this Zend generates this part of the form
<tr>
<td><label>Labeltext</label></td>
<td><input type="text" id="someid" name="somename" value="" /></td>
</tr>
And I want to workout that each formelement that created with this form decorator have a class eg.: "myclass" in base like this
<tr>
<td><label>Labeltext</label></td>
<td><input type="text" id="someid" name="somename" value="" class="myclass" /></td>
</tr>
The problem I see with this is, that the part you want to change is not a decorator, its the view itself. Now I may be out of loop on this one, but the way I see how this could be solved most easily is sub-classing (Making PHP Classes that extend from
Zend_Form_Element_*
) the input element types that you want to have this CSS class set, and setting this CSS class somewhere in the initialization part. Then just use your new PHP classes/elements where needed.