Using Zend_Form::setElementDecorators() with Zend_Config_Xml

View: New views
4 Messages — Rating Filter:   Alert me  

Using Zend_Form::setElementDecorators() with Zend_Config_Xml

by Ralf Eggert :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi again,

the usage of setElementDecorators() only effects all elements that have
been added to the form before. If I want to use other decorators than
these "defaults" for an element, I can simple add it after the usage of
setElementDecorators() and set the individual decorators.

Now this does not work when I use an Zend_Config_Xml object. I cannot
declare some <elements>, then set the <elementDecorators> values and
afterwards declare other <elements> in the XML file. If I try it, I get
an fatal error:

  Fatal error: Call to a member function getOrder() on a non-object in
  /home/devhost/phpmagazin/form/library/Zend/Form.php on line 824

When I use the <elementDecorators> Options before or after the
<elements> Options then the <elementDecorators> are used for each
element and the individual settings of <decorators> within the <options>
of an element are ignored.

The only solution is to declare all decorators for each element
separately and resign from the usage of <elementDecorators> with an XML
file.

Is it possible to amend Zend_Form to pass an array of elements to
setElementDecorators() so that individual decorator settings for an
element are not overwritten by setElementDecorators()?

Thanks and Best Regards,

Ralf

Re: Using Zend_Form::setElementDecorators() with Zend_Config_Xml

by Matthew Weier O'Phinney-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

-- Ralf Eggert <r.eggert@...> wrote
(on Thursday, 08 May 2008, 12:08 PM +0200):
> the usage of setElementDecorators() only effects all elements that have
> been added to the form before. If I want to use other decorators than
> these "defaults" for an element, I can simple add it after the usage of
> setElementDecorators() and set the individual decorators.
>
> Now this does not work when I use an Zend_Config_Xml object. I cannot
> declare some <elements>, then set the <elementDecorators> values and
> afterwards declare other <elements> in the XML file.

Correct; elementDecorators is intercepted in setOptions(), and executed
late. The assumption is that if elementDecorators is in your
configuration, you want the setting to apply to all elements.

Additionally, I'm suspecting Zend_Config_Xml is going to collapse the
multiple 'elements' sections in your config file to a single array.

> If I try it, I get an fatal error:
>
>   Fatal error: Call to a member function getOrder() on a non-object in
>   /home/devhost/phpmagazin/form/library/Zend/Form.php on line 824

Hmmm... Can you send some reproduce code for this?

> When I use the <elementDecorators> Options before or after the
> <elements> Options then the <elementDecorators> are used for each
> element and the individual settings of <decorators> within the <options>
> of an element are ignored.

Correct -- see above explanation.

> The only solution is to declare all decorators for each element
> separately and resign from the usage of <elementDecorators> with an XML
> file.
>
> Is it possible to amend Zend_Form to pass an array of elements to
> setElementDecorators() so that individual decorator settings for an
> element are not overwritten by setElementDecorators()?

This is an interesting idea. Could you put a request in the issue
tracker for this? It would be fairly trivial to implement, and would
solve a number of the issues people have reported regarding the usage of
setElementDecorators().

--
Matthew Weier O'Phinney
Software Architect       | matthew@...
Zend - The PHP Company   | http://www.zend.com/

Re: Using Zend_Form::setElementDecorators() with Zend_Config_Xml

by Ralf Eggert :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Matthew,

>> If I try it, I get an fatal error:
>>
>>   Fatal error: Call to a member function getOrder() on a non-object in
>>   /home/devhost/phpmagazin/form/library/Zend/Form.php on line 824
>
> Hmmm... Can you send some reproduce code for this?

I attached an XML file to this mail. I got the error with 1.5.1 release
but I bet it is due to the incorrect XML file with two <elements> Sections.

> This is an interesting idea. Could you put a request in the issue
> tracker for this? It would be fairly trivial to implement, and would
> solve a number of the issues people have reported regarding the usage of
> setElementDecorators().

Ok, done: http://framework.zend.com/issues/browse/ZF-3228

Thanks and best regards,

Ralf


<?xml version="1.0" encoding="UTF-8"?>
<config>
        <contactform3>
                <action>index/send3</action>
                <method>post</method>
                <elements>
                        <name>
                                <type>text</type>
                                <options>
                                        <size>40</size>
                                        <maxlength>40</maxlength>
                                        <label>Name</label>
                                        <required>true</required>
                                        <validators>
                                                <alpha>
                                                        <validator>Alpha</validator>
                                                </alpha>
                                                <stringlength>
                                                        <validator>StringLength</validator>
                                                        <options>
                                                                <min>1</min>
                                                                <max>40</max>
                                                        </options>
                                                </stringlength>
                                        </validators>
                                </options>
                        </name>
                        <email>
                                <type>text</type>
                                <options>
                                        <size>40</size>
                                        <label>E-Mail</label>
                                        <required>true</required>
                                        <validators>
                                                <emailaddress>
                                                        <validator>EmailAddress</validator>
                                                </emailaddress>
                                                <stringlength>
                                                        <validator>StringLength</validator>
                                                        <options>
                                                                <min>6</min>
                                                        </options>
                                                </stringlength>
                                        </validators>
                                </options>
                        </email>
                        <message>
                                <type>textarea</type>
                                <options>
                                        <rows>6</rows>
                                        <cols>40</cols>
                                        <label>Nachricht</label>
                                        <required>true</required>
                                        <filters>
                                                <striptags>
                                                        <validator>StripTags</validator>
                                                </striptags>
                                        </filters>
                                </options>
                        </message>
                </elements>
                <elementDecorators>
                        <viewhelper>
                                <decorator>ViewHelper</decorator>
                        </viewhelper>
                        <errors>
                                <decorator>Errors</decorator>
                        </errors>
                        <data>
                                <decorator>
                                        <data>HtmlTag</data>
                                </decorator>
                                <options>
                                        <tag>div</tag>
                                        <class>element</class>
                                </options>
                        </data>
                        <label>
                                <decorator>Label</decorator>
                                <options>
                                        <class>left</class>
                                </options>
                        </label>
                        <row>
                                <decorator>
                                        <row>HtmlTag</row>
                                </decorator>
                                <options>
                                        <tag>div</tag>
                                        <class>row</class>
                                </options>
                        </row>
                </elementDecorators>
                <elements>
                        <country>
                                <type>select</type>
                                <options>
                                        <size>1</size>
                                        <label>Land</label>
                                        <required>true</required>
                                        <multiOptions>
                                                <_>Bitte auswählen</_>
                                                <de>Deutschland</de>
                                                <at>Österreich</at>
                                                <ch>Schweiz</ch>
                                                <xx>anders</xx>
                                        </multiOptions>
                                </options>
                        </country>
                        <newsletter>
                                <type>checkbox</type>
                                <options>
                                        <label>Newsletter?</label>
                                        <checkedValue>yes</checkedValue>
                                        <uncheckedValue>no</uncheckedValue>
                                        <description>Ja, ich will ihn haben den Newsletter!</description>
                                        <decorators>
                                                <viewhelper>
                                                        <decorator>ViewHelper</decorator>
                                                </viewhelper>
                                                <errors>
                                                        <decorator>Errors</decorator>
                                                </errors>
                                                <data>
                                                        <decorator>
                                                                <data>HtmlTag</data>
                                                        </decorator>
                                                        <options>
                                                                <tag>span</tag>
                                                                <class>checkbox</class>
                                                        </options>
                                                </data>
                                                <label>
                                                        <decorator>Label</decorator>
                                                        <options>
                                                                <class>left</class>
                                                        </options>
                                                </label>
                                                <description>
                                                        <decorator>Description</decorator>
                                                        <options>
                                                                <tag></tag>
                                                        </options>
                                                </description>
                                                <row>
                                                        <decorator>
                                                                <row>HtmlTag</row>
                                                        </decorator>
                                                        <options>
                                                                <tag>div</tag>
                                                                <class>row</class>
                                                        </options>
                                                </row>
                                        </decorators>
                                </options>
                        </newsletter>
                        <gender>
                                <type>radio</type>
                                <options>
                                        <label>Geschlecht</label>
                                        <required>true</required>
                                        <multiOptions>
                                                <m>männlich</m>
                                                <w>weiblich</w>
                                                <x>sag ich nicht</x>
                                        </multiOptions>
                                </options>
                        </gender>
                        <send>
                                <type>submit</type>
                                <options>
                                        <label>Absenden</label>
                                        <decorators>
                                                <viewhelper>
                                                        <decorator>ViewHelper</decorator>
                                                </viewhelper>
                                                <data>
                                                        <decorator>
                                                                <data>HtmlTag</data>
                                                        </decorator>
                                                        <options>
                                                                <tag>div</tag>
                                                                <class>element</class>
                                                        </options>
                                                </data>
                                                <row>
                                                        <decorator>
                                                                <row>HtmlTag</row>
                                                        </decorator>
                                                        <options>
                                                                <tag>div</tag>
                                                        </options>
                                                </row>
                                        </decorators>
                                </options>
                        </send>
                </elements>
        </contactform3>
</config>

Re: Using Zend_Form::setElementDecorators() with Zend_Config_Xml

by Matthew Weier O'Phinney-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

-- Ralf Eggert <r.eggert@...> wrote
(on Friday, 09 May 2008, 02:32 PM +0200):

> Hi Matthew,
>
> >> If I try it, I get an fatal error:
> >>
> >>   Fatal error: Call to a member function getOrder() on a non-object in
> >>   /home/devhost/phpmagazin/form/library/Zend/Form.php on line 824
> >
> > Hmmm... Can you send some reproduce code for this?
>
> I attached an XML file to this mail. I got the error with 1.5.1 release
> but I bet it is due to the incorrect XML file with two <elements> Sections.

Verified -- when I moved the contents of the second 'elements' section
into the original, it worked correctly. I suspect what's happening is
that 'elements' is now being seen as an array with two members, with
each member an array of elements. Whatever the case, it's a malformed
config file.

> > This is an interesting idea. Could you put a request in the issue
> > tracker for this? It would be fairly trivial to implement, and would
> > solve a number of the issues people have reported regarding the usage of
> > setElementDecorators().
>
> Ok, done: http://framework.zend.com/issues/browse/ZF-3228

Thanks!



--
Matthew Weier O'Phinney
Software Architect       | matthew@...
Zend - The PHP Company   | http://www.zend.com/