Quickform ElementGrid - how to addRule()
| From: | Ben | Date: | Wed, 21 Mar 2007 15:54:45 +0000 |
| Subject: | Quickform ElementGrid - how to addRule() | ||
| References: | 1 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-26892@lists.php.net to get a copy of this message | ||
I am adding a grid of editable 'text' elements to a ElementGrid in HTML_Quickform. I would like to add validation rules ...
In the code below (***) I try and use "addRule" to no avail. Any ideas on how to make the validation of each element work?
Thanks.
{
$elementGrid =& $form->addElement('elementGrid', 'elementGrid', $prompt, array('actAsGroup' => true));
foreach($colheadings as $aheading) {
$elementGrid->addColumnName($aheading);
}
$numrows = count($data); // data contains 2 dimenensional array of
numbers$numcols = count($colheadings); // echo "addGrid:: numrows=$numrows numcols=$numcols
<br>";for ($i=0; $i<$numrows; $i++) { $row = null; for($j=0; $j<$numcols; $j++) {
$itemname = "grid_${name}_${i}_${j}";
$row[] =& HTML_QuickForm::createElement('text', $itemname, $itemname, array('size' => 10));
*** $form->addRule($itemname, "field must be numeric", 'numeric', null, 'server');
}
$gridrows[] = $row;
}
$elementGrid->setRows($gridrows);
}