Search code examples
phpvalidationpearquickform

PHP PEAR Quickform validation help


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?


Solution

  • check this site: link text

    and don't forget to add the validation

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