Zend 表单在运行时将元素所需选项更改为 false
我有一个表单并有两个文件上传元素。 一样
$data_file_one = $this->createElement('file','data_file_one');
$data_file_one->setRequired(true)
->addValidator('Extension', false, 'csv')
->setDestination($filepath);
就像两者都设置为必需的 true 。我对新帖子和编辑帖子使用相同的表格。当它用于编辑文件时,上传不应该是强制的,必须设置为 required false。所以,我需要改变
setRequired(true) 到 setRequired(false)
当调用编辑操作来加载表单并更改此元素选项时,我该怎么办?
提前致谢。
I have a form and having two file upload elements. it is like
$data_file_one = $this->createElement('file','data_file_one');
$data_file_one->setRequired(true)
->addValidator('Extension', false, 'csv')
->setDestination($filepath);
Both are set to required true. I use the same form for new post and edit posts. When it is used for editing the file upload should not be mandatory and must be set to required false. So, I need to change
setRequired(true) to setRequired(false)
How can I do when edit action is called to load form and change this element option?
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Zend_Forms 有一个名为 getElement 的方法,允许您通过名称从表单中检索元素。这使您能够在将元素呈现给用户之前修改其默认值。
例如,要将字段从必填字段更改为可选字段,您可以执行以下操作:
Zend_Forms have a method called getElement that allow you to retrieve an element from a form by its name. This gives you the ability to modify an element's default value before rendering it to the user.
For example, to change a field from being required to being optional, you can do the following: