需要用于 Html-Select 和 Html-Input 组的 Php Quickform Grouprule

发布于 2024-10-08 14:55:59 字数 713 浏览 0 评论 0原文

我目前正在开发一个大型 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,通过以下方式验证该组:

  1. 如果两个字段都为空 ->错误。
  2. 如果其中一个字段有值,则另一个字段必须为空,否则 ->错误。
  3. 如果两个字段都有值,则它们必须匹配,否则 ->错误。

有人可以向我解释一下我怎样才能做到这一点吗?我已经尝试编写自定义规则,但不知何故代码从未调用我的验证方法。

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:

  1. If both fields are empty -> error.
  2. If one of the fields has a value in it, the other one must be empty, otherwise -> error.
  3. 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

人生百味 2024-10-15 14:55:59

如果您使用的是 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).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文