For Programmers: Free Programming Magazines  


Home > Archive > PHP Pear > March 2007 > Re: [PEAR] Quickform ElementGrid - how to addRule()









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Re: [PEAR] Quickform ElementGrid - how to addRule()
Justin Patrin

2007-03-22, 4:01 am

On 3/21/07, Ben <ben@giantsteps.com> wrote:
> 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);
> }
>


Looks like that was one of the things I never tested. Rules on element
in an elementGrid are currently not supported (and some quick hacking
hasn't shown me a solution).

I suggest you try addFormRule() for now.

--
Justin Patrin
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com