Removing Formatting from Zend_Form_Element_File

I am trying to remove the dt and dd decorators due to a file element.

I usually apply $element->setDecorators(array(array('ViewHelper')));to a form element.
However, this is not applicable in the case Zend_Form_Element_Fileof error output.

Any advice would be appreciated,

thanks

+3
source share
3 answers

First you need to remove the DtDdWrapper decorator from the form. Secondly, from each element, get a Label decorator and set the tag property to null, and finally, remove the HtmlTag decoder for each element.

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 as an important element of the File Element decor intact, with the exception of the rest of all your elements.

+2
source

, , , . , ZF.

<?php
$form->setDecorators(array(
    array('ViewScript', array('viewScript' => 'form.phtml'))
));
?>

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>
+1

try the following:

$myFormElement->removeDecorator('DtDdWrapper');
0
source

Source: https://habr.com/ru/post/1713936/


All Articles