Reputation: 457
I have been trying to create a custom form with Zend_Form and Decorators, the desired html formatting is as follows:
<form enctype="application/x-www-form-urlencoded" method="post" action="">
<div class="login_bx">
<div id="txtAccount-label" class="txt_field">
<label for="txtAccount" class="required">Account ID:</label>
</div>
<div class="inp_field">
<input type="text" name="txtAccount" id="txtAccount" value="" style="width:250px">
</div>
</div>
</form>
the contents of Zend_Form class are as follows:
$account = new Zend_Form_Element_Text('txtAccount');
$account -> setLabel('Account ID:')
-> setAttrib('style','width:250px')
-> setRequired(true)
-> addValidator('NotEmpty', true);
$this->setDecorators(array(
'FormElements',
array(
'HtmlTag',
array(
'tag' => 'div',
'class' => 'login_bx',
)
),
'Form',
array('FormErrors', array(
'placement' => 'prepend',
'markupElementLabelEnd' => '</strong>',
'markupElementLabelStart' => '<strong>',
'markupListStart' => '<div class="errors_list" id="msg">',
'markupListEnd' => '</div>',
'markupListItemStart' => '<div class="error_item">',
'markupListItemEnd' => '</div>'
))
));
$this->addElements(array($account));
$this->setElementDecorators(array(
'ViewHelper',
//'Errors',
array(array(
'data' => 'HtmlTag'
), array(
'tag' => 'div',
'class' => 'inp_field'
)
),
array('Label', array(
'tag' => 'div',
'class' => 'txt_field'
))
));
the current html rendered is as follows:
<form enctype="application/x-www-form-urlencoded" method="post" action="">
<div class="login_bx">
<div id="txtAccount-label">
<label for="txtAccount" class="txt_field required">Account ID:</label>
</div>
<div class="inp_field">
<input type="text" name="txtAccount" id="txtAccount" value="" style="width:250px">
</div>
</div>
</form>
I couldn't figure out how to add class to the DIV wrapping the label
Upvotes: 0
Views: 180
Reputation: 3950
instead of
array('Label', array(
'tag' => 'div',
'class' => 'txt_field'
))
use
array('Label', array(
'tag' => 'div',
'tagClass' => 'txt_field'
))
Upvotes: 1
Reputation: 1122
Try this
$name = new Zend_From_Element_Text("txtName");
$name->setOptions(array('class'=>'css class name'));
http://forums.zend.com/viewtopic.php?f=69&t=1367
or this
how to add special class for labels and errors on zend form elements?
Upvotes: 0