-- chinaski <[EMAIL PROTECTED]> wrote
(on Wednesday, 16 April 2008, 10:41 AM -0700):
> 
> 
> 
> Matthew Weier O'Phinney-3 wrote:
> > 
> > 
> >> I thought that adding the prefex path to the form itself made the path
> >> available to all of the elements? Am I missing something?
> > 
> > It does... as long as:
> > 
> >   * you're adding the prefix path *before* creating elements
> >   
> >   * AND you're creating the elements via the form object's addElement()
> >     or createElement() methods
> > 
> > 
> Here is my form code:
> class forms_TestvalForm extends Zend_Form
> {
>    public function __construct($options = null)
>    {
>       parent::__construct($options);
>       $this->addElementPrefixPath('My','My/');
>       $this->setName('testval');
> 
> 
>       $testing = new Zend_Form_Element_Text('testing');
>       $testing->setLabel('Test Value')
>       ->setRequired(true);

The problem is right here: for the form's elementPrefixPath setting to
have any effect on an element, the element must be created using the
form object's addElement() or createElement() methods. Try this instead:

    $testing = $this->createElement('text', 'testing');

and you should see better results (you'll need to do it for all
methods). If you use createElement(), don't forget to attach the
elements later using addElement(), addElements(), or setElements().


>       //$testing->addPrefixPath('My','My/');
> 
>       $testing->addValidator('TestVal');
>       $this->addElement($testing);
> 
> 
>       $submit = new Zend_Form_Element_Submit('submit');
>       $submit->setLabel('submit');
> 
>       $this->addElement($submit);
> 
>       $this->setAction('/formtest/testval/')
>       ->setMethod('post');
>    }
> }
> 
> If I uncomment //testing->addPrefixPath('My,'My/'); it works; otherwise not.
> Any suggestions as to what I'm doing wrong here?

-- 
Matthew Weier O'Phinney
Software Architect       | [EMAIL PROTECTED]
Zend - The PHP Company   | http://www.zend.com/

Reply via email to