2012-03-18 19 views
2


我得到這個,這不打印驗證錯誤:爲什麼Form-> file()不顯示驗證錯誤?

<?php echo $this->Form->file('fileurl_file', array('label' => '', 'class' => 'input-text')); ?> 

如果我將其更改爲

<?php echo $this->Form->input('fileurl_file', array('label' => '', 'class' => 'input-text')); ?> 

這表明驗證錯誤。

我做錯了什麼?
Thx!

編輯:
我接過來一看介紹的表單助手類。我發現,即使是有「文件」方法時不中實現不提供,如果逮住任何打印錯誤的支持。
然後,我看到「輸入」方法在某些時候作爲參數「類型」(我猜這也在文檔中提到過,但我沒有閱讀全部內容),它可以來自「文本」 ,「文件」,「選擇」 ...
所以,這就是我設法讓我的文件稱輸入工作,因爲我需要:

<?php echo $this->Form->input('fileurl_file', array('type' => 'file', 'label' => '', 'class' => 'input-text')); ?> 
+0

你可以顯示'$ this-> Form-> create'代碼的形式以及你如何在Model中進行驗證? – 2012-03-18 12:14:07

+0

<?php echo $ this-> Form-> create('Meta',array('class'=>'form-default section','method'=>'post','enctype'=>'multipart/form -數據')); ?> – Michael 2012-03-18 12:34:47

+0

這是create(),驗證是在BehaviourModel中完成的,但它並不重要,因爲正如我所說的,工作與非工作(顯示錯誤)之間的區別在於創建文本/文件輸入。 – Michael 2012-03-18 12:37:40

回答

1

驗證工作

表單助手::輸入做了很多工作,包括輸出驗證錯誤。

FormHelper :: file只輸出一個文件,僅此而已。你必須使用輸出

<?php echo $this->Form->file('fileurl_file', array('label' => '', 'class' => 'input-text')); 
    echo $this->Form->error('fileurl_file'); 
    ?> 

我希望它會爲你工作的錯誤自己