Reputation:
I am trying to remove the dt and dd decorators from around a file element.
Usually I apply $element->setDecorators(array(array('ViewHelper')));
to the form element.
However this is not applicable in the case of Zend_Form_Element_File
as an error is output.
Any advice would be appreciated,
Thanks
Upvotes: 3
Views: 839
Reputation: 7640
I find if I need to remove more than a couple of decorators, it is easier to just reimplement the entire form's view. Faster to program, instead of wrestling with ZF.
<?php
$form->setDecorators(array(
array('ViewScript', array('viewScript' => 'form.phtml'))
));
?>
And then the form.phtml:
<?php
$form = $this->element;
?>
<?php if(sizeof($form->getErrorMessages()) != 0) :?>
<div class="error-message"><?php echo $this->formErrors($form->getErrorMessages());?></div>
<?php endif; ?>
<form
action="<?php echo $this->escape($form->getAction()); ?>"
method="<?php echo $this->escape($form->getMethod()); ?>"
id="<?php echo $this->escape($form->getId()); ?>">
<table>
<tr>
<th><?php echo $this->escape($email->getLabel()); ?></th>
<td><?php echo $email->renderViewHelper(); ?>
<?php
if ($email->hasErrors()) {
echo $this->formErrors($email->getMessages());
}
?>
</td>
</tr>
</table>
</form>
Upvotes: 1
Reputation: 660
You firstly need to remove the DtDdWrapper decorator from the form. Secondly, from each element, get the Label decorator, and set the tag property to null, and lastly, for each element, remove the HtmlTag decorator.
ala:
<?php
class My_Form extends Zend_Form
{
public function init()
{
//Add elements first.
$this->removeDecorator('HtmlTag');
foreach ($this->getElements() as $element) {
$element->getDecorator('Label')->setTag(null);
$element->removeDecorator('HtmlTag');
$element->removeDecorator('DtDdWrapper');
}
}
}
This will leave the file element's important File Element decorator intact, while stripping the others from all your elements.
Upvotes: 2
Reputation: 20726
try this :
$myFormElement->removeDecorator('DtDdWrapper');
Upvotes: 0