暂停 Zend Framework 上的文件验证
目前,在我的应用程序中,我有一个表单,要求用户上传要用作徽标的图像文件。我想允许用户通过不提供文件(只需按浏览器中的上传按钮)将其重置为空。
在这种情况下,唯一剩下的就是在不包含文件时暂停文件验证。 目前,我从 Zend_Validate_File_Upload 类中收到 self::NO_FILE 错误。
有没有办法暂停验证,以便在没有提供文件的情况下不会检查任何内容?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
据我所知,禁用验证器内的特定验证是不可能的。您必须将其子类化并修改相应的部分。但是,我假设您正在检查表单在控制器中是否有效,
如果是这样,您可以使用
Zend_Form
的getErrors()
方法。如果是NO_FILE
,则将该操作转发到重置徽标的操作。就我个人而言,我会找到一个专门的按钮来删除徽标,但这是更好的选择。
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_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.