需要用于 Html-Select 和 Html-Input 组的 Php Quickform Grouprule
我目前正在开发一个大型 html 表单。我使用 Php Quickform 来创建和验证它。该表单有几个组,由输入文本字段和选择字段组成。其中一个组的代码
如下所示:
$autoren = array("0" => "", "1" => "Bob", "2" => "Harry", "3" => "Autor 3");
$arr[] = &HTML_QuickForm::createElement('text', 'autorT', 'AutorText', array('size' => 37, 'maxlength' => 50));
$arr[] = &HTML_QuickForm::createElement('select', 'autorO', 'AutorOptions', $autoren);
$form->addGroup($arr, 'Autoren', 'Autor:', '<br />');
我迫切需要某种规则/GroupRule,通过以下方式验证该组:
- 如果两个字段都为空 ->错误。
- 如果其中一个字段有值,则另一个字段必须为空,否则 ->错误。
- 如果两个字段都有值,则它们必须匹配,否则 ->错误。
有人可以向我解释一下我怎样才能做到这一点吗?我已经尝试编写自定义规则,但不知何故代码从未调用我的验证方法。
i'm currently working on a big html form. I use Php Quickform to create and validate it. The form has a few Groups that consist of a Input-Textfield and a Select-field. The code for one of the groups
looks like this:
$autoren = array("0" => "", "1" => "Bob", "2" => "Harry", "3" => "Autor 3");
$arr[] = &HTML_QuickForm::createElement('text', 'autorT', 'AutorText', array('size' => 37, 'maxlength' => 50));
$arr[] = &HTML_QuickForm::createElement('select', 'autorO', 'AutorOptions', $autoren);
$form->addGroup($arr, 'Autoren', 'Autor:', '<br />');
I'm in desperate need of some kind of Rule/GroupRule that validates this group in the following way:
- If both fields are empty -> error.
- If one of the fields has a value in it, the other one must be empty, otherwise -> error.
- If both fields have values in them, they must match, otherwise -> error.
Can somebody explain to me how i can accomplish that? I already tried to write a custom rule, but somehow the code never called my validate method.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
更多
发布评论
评论(1)
如果您使用的是 HTML_QuickForm2,则使用
_and()
和_or()
链接规则可以实现您想要的效果。对于 QF1,这是不可能的(除非在表单上使用回调规则)。If you're using HTML_QuickForm2, then chaining the rules with
_and()
and_or()
makes possible what you want. With QF1, it's not possible (except using a callback rule on the form).