Zend 表单验证
我正在使用 Zend Form 创建动态表单。
我也有 Zend Form 验证。
尝试动态删除验证,但没有取得任何成功。
你能帮我删除 Zend Validation 吗?
下面是我的删除验证代码:
$toRemValArray = array();
$toRemValArray[0] = 'ele_4af42ceac7810';
if(isset($_POST['btnPost_x'])){
if ($form->isValid($_POST)) {
$allElements = $form->getElements();
foreach($allElements as $val){
if(in_array('ele_4af42ceac7810',$toRemValArray)){
$value = $form->getElement($val->getName());
$value->removeValidator('ele_4af42ceac7810');
}
}
}
}
让我知道我的代码是否有任何问题
谢谢 穆罕默德·塔雷克
I am using Zend Form to create dynamic form.
I have Zend Form validation too.
Trying to remove Validation dynamically, but not getting any success.
Can you plz help me to remove Zend Validation.
Bellow is my code for remove validation :
$toRemValArray = array();
$toRemValArray[0] = 'ele_4af42ceac7810';
if(isset($_POST['btnPost_x'])){
if ($form->isValid($_POST)) {
$allElements = $form->getElements();
foreach($allElements as $val){
if(in_array('ele_4af42ceac7810',$toRemValArray)){
$value = $form->getElement($val->getName());
$value->removeValidator('ele_4af42ceac7810');
}
}
}
}
Let me know whether my code is having any issue
Thanks
Mohammad Tareque
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您应该在调用$form->isValid()之前删除验证器。
You should remove the validator BEFORE calling $form->isValid().
我想出的解决方案是重写表单类上的
isValid
方法,并删除密码字段上的验证器(如果密码字段留空):$this->form
指的是通过组合扩展的表单,该解决方案在扩展 Zend Form 后代类时也有效。附带说明一下,如果密码字段是必填,则此解决方案将不起作用
The solution I came up with was overriding the
isValid
method on my form class and removing the validator on the password field if it was left blank:The
$this->form
is referred to the form being extended by composition, the solution works when extending a Zend Form descendent class as well.Just a side note, this solution won't work if the password field is required
您的代码正在按名称删除验证器,
这通常类似于
NotEmpty
或Regex
,而不是元素名称。也许您想要
此外,+1 Ismael - 您应该在调用
$form->isValid()
之前将其删除Your code is removing a validator by name
This is typically something like
NotEmpty
orRegex
as opposed to the element name.Maybe you want
Also, +1 Ismael - you should remove it prior to calling
$form->isValid()