开发者

Suspend file validation on Zend Framework

Currently on my application I have a form where I ask the user to upload an image file to be used as a logo. I want to allow the user to reset that to nothing by supplying no file (by just pressing the upload button from the browser).

In this scenario the only thing left is to suspend file va开发者_运维百科lidation when no file is included. Currently I get the self::NO_FILE error from the Zend_Validate_File_Upload class.

Is there any way to suspend the validation so that nothing will be checked if no file has been provided?


Disabling a specific validation inside the Validator is not possible to my knowledge. You would have to subclass it and modify the correspoding part. However, I assume you are checking if the form is valid in a controller with something like

$form->isValid( // ...

If so, you can check which error was returned on a failed validation with Zend_Form's getErrors() method. If that is NO_FILE then, forward the action to the action resetting the logo.

Personally, I would a find a dedicated button to remove a logo the better choice though.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜