PHP PEAR Quickform 验证帮助

发布于 2024-08-04 12:18:44 字数 859 浏览 2 评论 0原文

我正在使用 PEAR 的 Quickform 包来验证我拥有的表单,我需要帮助将验证规则应用于一组复选框。

$subjectArea[] = HTML_QuickForm::createElement('advcheckbox', 'SubjectArea', null, 'Student', 'id="subjectareastudent"', 'Student');
$subjectArea[] = HTML_QuickForm::createElement('advcheckbox', 'SubjectArea', null, 'Course', 'id="subjectareacourse"', 'Course');
$subjectArea[] = HTML_QuickForm::createElement('advcheckbox', 'SubjectArea', null, 'Faculty', 'id="subjectareafaculty"', 'Faculty');
$subjectArea[] = HTML_QuickForm::createElement('advcheckbox', 'SubjectArea', null, 'Other', 'id="subjectareaother"', 'Other');

$form->addGroup($subjectArea, 'subjectArea', 'Subject Area:');
$form->addRule('SubjectArea', 'Please specify a subject area', 'required');

现在,当没有选中任何复选框时,表单不会显示任何错误。根据我在文档中读到的内容,当您希望将验证规则应用于整组元素时,您应该使用 addRule。

有什么想法为什么这不起作用吗?

I am using PEAR's Quickform package to validate a form I have, I need help getting a validation rule applied to a group of checkboxes.

$subjectArea[] = HTML_QuickForm::createElement('advcheckbox', 'SubjectArea', null, 'Student', 'id="subjectareastudent"', 'Student');
$subjectArea[] = HTML_QuickForm::createElement('advcheckbox', 'SubjectArea', null, 'Course', 'id="subjectareacourse"', 'Course');
$subjectArea[] = HTML_QuickForm::createElement('advcheckbox', 'SubjectArea', null, 'Faculty', 'id="subjectareafaculty"', 'Faculty');
$subjectArea[] = HTML_QuickForm::createElement('advcheckbox', 'SubjectArea', null, 'Other', 'id="subjectareaother"', 'Other');

$form->addGroup($subjectArea, 'subjectArea', 'Subject Area:');
$form->addRule('SubjectArea', 'Please specify a subject area', 'required');

As it is now, the form does not show any errors when no checkboxes are checked. From what I have read in the documentation, you are supposed to use addRule when you want a validation rule applied to a whole group of elements.

Any ideas why this is not working?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

香草可樂 2024-08-11 12:18:44

检查这个网站:
链接文本

并且不要忘记添加验证

if ($form->validate()) {
echo 'hello';
}

check this site:
link text

and don't forget to add the validation

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