-- fsmmls <[EMAIL PROTECTED]> wrote
(on Tuesday, 30 September 2008, 01:46 PM +0200):
> 2008/9/30 Matthew Weier O'Phinney <[EMAIL PROTECTED]>
> > -- Jan Smit <[EMAIL PROTECTED]> wrote
> > (on Tuesday, 30 September 2008, 01:22 AM +0200):

<snip>

> I mean that I added 3 empty arrays to this line:
> $oEmail = new Zend_Dojo_Form_Element_ValidationTextBox('email',
> array(), array(), array());
> 
> But that was just a wild guess, after a few hours of trying and trying...

Very wild guess. The ValidationTextBox *view helper* takes for
arguments, but here you're instantiating a form element. Apples and
oranges

<snip>

> Okay, I already thought it would be possible.
> But I am still having this error.
> 
> I posted my code here: http://pastebin.com/m193743a8
> This is a method which i made inside my contactForm controller. Maybe
> you could have a look at it?
> 
> Also, do you know a better way to create this form? I mean, I now had
> some issues with the submit button. I had to add it separate because
> it didn't need the <label for="bla"> tag. But that is not the most
> important thing for now.

Several things I see that could be done differently with that form.

First, just use Zend_Dojo_Form -- it's simpler and easier than using
Zend_Form and then Dojo-enabling it. It also has the side effect of
ensuring that the Dojo view helper path is added to the view.

Second, use addElement() as a factory instead of passing in concrete
element instances. This takes advantage of the plugin architecture,
which will allow you to create your own local overrides of the various
elements later if you want to.

Third, instead of creating the form programmatically within a helper
method of your controller, instead create your own form class extending
Zend_Dojo_Form:

    class ContactForm extends Zend_Dojo_Form
    {
        public function init()
        {
            $this->setDecorators(array(
                'FormElements',
                array('HtmlTag', array('tag' => 'ul', 'id' => 'contact')),
                'Form',
            ));
            
            $this->addElement('text', 'name', array(
                'validators' => array(
                    array('validator' => 'Alnum', 'options' => array(true)),
                ),
                'required' => true,
                'label'    => 'Your name:',
            ));

            $this->addElement('ValidationTextBox', 'email', array(
                'validators' => array('EmailAddress'),
                'required'   => true,
                'label'      => 'Your Email',
                'attribs'    => array('Just' => 'some', 'useless' => 'values'),
                'invalidMessage' => 'Invalid',
            ));

            // ...
        }
    }

Then, in your controller, have your getForm() method simply instantiate
and return the form.

-- 
Matthew Weier O'Phinney
Software Architect       | [EMAIL PROTECTED]
Zend Framework           | http://framework.zend.com/

Reply via email to