Reputation: 2171
I'm new to Zend, and beginner in php. I have a form generating several Elements. I have already add Decorators to have each of them in a div :
$element->addFilter('StringTrim')->addDecorators(array('clearfix'=>new Zend_Form_Decorator_HtmlTag(array('tag'=>'div','class'=>'clearfix'))));
My generated html looks like that :
<div class="clearfix">
<dt id="email-label"><label for="email" class="optional">Email</label></dt>
<dd id="email-element">
<input type="text" name="email" id="email" value="" class="text" maxlength="100">
</dd>
</div>
I want to add a class to the dd tag to have that :
<div class="clearfix">
<dt id="email-label"><label for="email" class="optional">Email</label></dt>
<dd class="clearfix" id="email-element">
<input type="text" name="email" id="email" value="" class="text" maxlength="100">
</dd>
</div>
EDIT :
/* ################################### email ################################### */
$email = new Zend_Form_Element_Text('email');
$email ->setLabel("Email");
$email ->setAttrib('class','text');
// $email ->setRequired(true);
$email ->addValidator('EmailAddress');
$email ->setFilters(array('StringTrim', 'StringToLower'));
$email ->addFilter('StringTrim')->addDecorators(array('clearfix'=>new Zend_Form_Decorator_HtmlTag(array('tag'=>'div','class'=>'clearfix'))));
$email ->addValidator('StringLength', false, array(0, 100));
$email ->setAttrib('maxlength', '100');
$this ->addElement($email);
Someone have an idea ? Thanks!
Upvotes: 2
Views: 1190
Reputation: 5651
Here's another way without using the decorators.
You can add this in your form class.
$this->setElementDecorators(array(
'ViewHelper'
));
And render your form like this in your view.
<form class="your-class" id="<?php echo $this->form->getAttrib('id'); ?>" name="<?php echo $this->form->getAttrib('name'); ?>" action="<?php echo $this->escape($this->form->getAction()); ?>" method="<?php echo $this->escape($this->form->getMethod()); ?>">
<div class="something">
<?php echo $this->form->getElement('element')->getLabel(); ?>
</div>
<div class="something">
<?php echo $this->form->getElement('element'); ?>
</div>
</form?
Upvotes: 0
Reputation: 5772
Try this
$deco_html_tag = $element->getDecorator('HtmlTag');
$deco_html_tag->setOption('class', 'clearfix');
Upvotes: 1
Reputation: 12236
try this:
$element = new Zend_Form_Element_Text('email');
$element->addDecorators(array(array('HtmlTag',array('tag' => 'dd', 'class' => 'yourclass' )));
Upvotes: 1