Quickform checkboxes/groups and client validation
| From: | Graeme Merrall | Date: | Sun, 12 Oct 2003 00:18:24 +0000 |
| Subject: | Quickform checkboxes/groups and client validation | ||
| Groups: | php.pear.general | ||
| Request: | Send a blank email to pear-general+get-8375@lists.php.net to get a copy of this message | ||
Hi. I've been poking around in Quickforms trying to get client-side
validation working for a group of checkboxes.
From the example code:
$checkbox[] = &HTML_QuickForm::createElement('checkbox', 'A', null,
'A');
$checkbox[] = &HTML_QuickForm::createElement('checkbox', 'B', null,
'B');
$checkbox[] = &HTML_QuickForm::createElement('checkbox', 'C', null,
'C');
$checkbox[] = &HTML_QuickForm::createElement('checkbox', 'D', null,
'D');
$form->addGroup($checkbox, 'destination', 'Destination:',
array(' ',
'<br />'));
$form->addGroupRule('destination', 'Please check at least two boxes',
'required', null, 2);
If I make add 'client' to the addGroupRule() method, QuickForms outputs
Javascript on the page as expected
var field = frm.elements['destination'];
var regex = /(\s|\S)/;
if (!regex.test(value) && !errFlag['destination']) {
errFlag['destination'] = true;
_qfMsg = _qfMsg + '\n - Please check at least two boxes';
}
However. this is not correct code for checkboxes. Looking at QuickForm.php
is appears that because I've created a group, this is the javascript that is
displayed as opposed to the javascript for a checkbox.
Is there was way to create the group of checkboxes yet still have client
side validation?
I'm attempting this using the Smart static stuff BTW although I don't expect
this to make any difference.
Cheers,
Graeme