2009-07-30 13 views
3

ファイル要素の周りからdtおよびddデコレータを削除しようとしています。Zend_Form_Element_Fileから書式を削除する

通常、私は$element->setDecorators(array(array('ViewHelper')));をフォーム要素に適用します。
ただし、エラーが出力されるためZend_Form_Element_Fileの場合は適用されません。

何かアドバイスをいただければ幸い、

おかげ

+0

いただきましエラー? – UpTheCreek

答えて

0

はこれを試してみてください。

$myFormElement->removeDecorator('DtDdWrapper'); 
2

あなたは、まずフォームからDtDdWrapperデコレータを削除する必要があります。 次に、各要素からLabelデコレータを取得し、タグプロパティをnullに設定します。 最後に、各要素について、HtmlTagデコレータを削除します。

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'); 
     } 
    } 

} 

これは、そのままファイル要素の重要なファイルの要素デコレータを残します。

+0

このソリューションをありがとう:) – Andy

1

複数のデコレータを削除する必要がある場合は、フォーム全体のビューを再実装する方が簡単です。 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> 
関連する問題