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 validation 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
If so, you can check which error was returned on a failed validation with
Zend_Form‘sgetErrors()method. If that isNO_FILEthen, 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.