-- iceangel89 <[email protected]> wrote
(on Tuesday, 05 May 2009, 06:37 PM -0700):
> i found out that validation only works if the $this->t = new ... ("t" ...)
> both "names" must be the same
> 
> $this->t = new Zend_Form_Element_Text("t", array (
>     ...
>     'validators' => array('Int', new Lab_Validator_AllocationBalance())
> ));
> 
> how can i fix this? cos i am dynamically adding elements to a display grp
> using 
> 
> $this->getDisplayGroup("labAllocation")->addElement(new
> Zend_Form_Element_Text("balance", array ( ... ...
> 
> so they have no "variable names" as in $this->var so i cant get validation
> to work?

You should add the elements to the form, and then create the display
group and pass in the elements you wish to use:

    class FooForm extends Zend_Form
    {
        public function init()
        {
            $this->addElement('text', 't', array(
                'prefixPaths' => array(
                    'validate' => array(
                        'Lab_Validator' => 'Lab/Validator/',
                    ),
                ),
                'validators' => array(
                    'Int',
                    'AllocationBalance',
                ),
            ));

            $this->addDisplayGroup(array('t'), 'labAllocation');
        }
    }

The elements belong to the form, and the display group is just a way to
group particular elements for display purposes. If you want to group
them for semantic purposes, use a sub form.

-- 
Matthew Weier O'Phinney
Project Lead            | [email protected]
Zend Framework          | http://framework.zend.com/

Reply via email to