views:

92

answers:

1

Hi, 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?

A: 

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.

Gordon
Having a dedicated button removing the logo, is exactly what I thought a couple of hours after writing that post. I think it is the more intuitive solution. But it would be nice to suspend, take for an example some sites where you can optionally add your avatar.
dimitris mistriotis
@dimitris I haven't worked with ZF Upload Form Elements yet, but isn't making it optional achieved by just not setting 'required' to the form element?
Gordon
@Gordon, I tried it but did not to work, actually the same error occurred (no difference) I implemented the "new button" approach which kind of solved my problem. I will try it again tomorrow.
dimitris mistriotis