group validation in quickform query
| From: | rav k | Date: | Thu, 21 Dec 2006 16:48:56 +0000 |
| Subject: | group validation in quickform query | ||
| Groups: | php.pear.general | ||
| Request: | Send a blank email to pear-general+get-26171@lists.php.net to get a copy of this message | ||
Hi
I have a question about validating group entries in quickform:
This is the example in the documentation:
$id[] = &HTML_QuickForm::createElement('text', 'username', 'Username');
$id[] = &HTML_QuickForm::createElement('text', 'code', 'Code');
$form->addGroup($id, 'id', 'Your ID:', '-');
// Validation rules per element
$rule['username'][] = array('Username is required', 'required');
$rule['username'][] = array('Username contains only letters', 'lettersonly');
$rule['username'][] = array('Username has between 5-8 characters', 'rangelength', array(5, 8));
$rule['code'][] = array('Code is required', 'required');
$rule['code'][] = array('Code contains numbers only', 'regex', '/^\d+$/');
$rule['code'][] = array('Code is 5 numbers long', 'rangelength', array(5, 5));
$form->addGroupRule('id', $rule);
But what am I supposed to do if I am dynamically adding elements such as textboxes or textareas??? How can I make a rule for that.
Heres my example:
while ($row = $res->fetchRow(MDB2_FETCHMODE_ASSOC)) {
$skills[] = &HTML_QuickForm::createElement('advcheckbox', $row['skillid'], null,'<b>'.$row['skillname'].'</b>',
'onclick="alert(this.form.elements.length)";
onclick="SetState(this, this.form.elements['."'skills[txt".$row['skillname']."]'".'])"'
, $row['skillid']);
$skills[] = &HTML_QuickForm::createElement('textarea', 'txt'.$row['skillname'], $row['skillname'], 'disabled rows=3 cols=70');
}
$form->addGroup($skills, 'skills', 'Your requirements:', '<br />');
All that code adds x number of checkboxes and textareas.
Then:
$form->addGroupRule('skills', 'You need at least 1 requirement and explain it', 'required', null, 1);
To make sure at least one checkbox is ticked before posting...
But I also want to make sure the text written in the textarea doesn't go over 200 words. So how can I do that????
Please help!
www.bitesoftware.com - software for a better lifestyle
_________________________________________________________________
Think you're a film buff? Play the Movie Mogul quiz and win fantastic prizes! http://www.msnmoviemogul.com