How to use existing decorators in Zend Framework?
Following code:
$this->addElement('text', 'email', 开发者_运维问答array(
'label' => 'Your email address:',
));
$this->addElement('submit', 'submit', array(
'label' => 'Sign Guestbook',
));
produces following HTML:
<form enctype="application/x-www-form-urlencoded" action="" method="post">
<dl class="zend_form">
<dt id="email-label">
<label for="email" class="optional">Your email address:</label>
</dt>
<dd id="email-element">
<input type="text" name="email" id="email" value="" />
</dd>
<dt id="submit-label">
 
</dt>
<dd id="submit-element">
<input type="submit" name="submit" id="submit" value="Sign Guestbook" />
</dd>
</dl>
</form>
I know, I can write my own decorators, but I would like to know, how to use existing decorators, to create following HTML:
<form enctype="application/x-www-form-urlencoded" action="" method="post">
<div>
<label for="email" class="optional">Your email address:</label>
<input type="text" name="email" id="email" value="" class="my_class" />
</div>
<div>
<input type="submit" name="submit" id="submit" value="Sign Guestbook" class="my_class" />
</div>
</form>
No <dl/>
, <dt/>
, <dd/>
, added class
attribute.
For example, I know, how to remove surrounding <dl/>
tag:
$this->addDecorator('FormElements')
->addDecorator('Form');
Are other changes possible without writing custom decorators?
This (append this array to your parameters array, which now consists of only one label option) should help with your email field:
'class' => 'my_class',
'decorators' => array(
'ViewHelper',
'Errors',
'Label',
array('HtmlTag', array('tag' => 'div'))
)
And the same without Label
- for submit.
You can use the HtmlTag decorator and pass which tag to use as a parameter.
All available decorators are listed here: http://framework.zend.com/manual/en/zend.form.standardDecorators.html
精彩评论