Search code examples
zend-formzend-form-elementzend-config-xml

XML configuration of Zend_Form: child nodes and attributes not always equal?


A set of forms (using Zend_Form) that I have been working on were causing me some headaches trying to figure out what was wrong with my XML configuration, as I kept getting unexpected HTML output for a particular INPUT element. It was supposed to be getting a default value, but nothing appeared.

It appears that the following 2 pieces of XML are not equal when used to instantiate Zend_Form:

Snippet #1:

<form>
  <elements>
    <test type="hidden">
      <options ignore="true" value="foo"/>
    </test>
  </elements>
</form>

Snippet #2:

<form>
  <elements>
    <test type="hidden">
      <options ignore="true">
        <value>foo</value>
      </options>
    </test>
  </elements>
</form>

The type of the element doesn't appear to make a difference, so it doesn't appear to be related to hidden fields.

Is this expected or not?


Solution

  • As it was rather quiet on here, I took a look further into the source code and documentation.

    On line 259 of Zend_Config_Xml, the SimpleXMLElement object attributes are converted to a string, resulting in:

    options Object of: SimpleXMLElement 
        @attributes Array [2]   
            label   (string:7) I can't see this because 
            value   (string:21) something happens to this
    

    becoming

    options (string:21) something happens to this
    

    So, I hunted through the documentation only to find that "value" is a reserved keyword when used as an attribute in an XML file that is loaded into Zend_Config_Xml:

    Example #2 Using Tag Attributes in Zend_Config_Xml

    "..Zend_Config_Xml also supports two additional ways of defining nodes in the configuration. Both make use of attributes. Since the extends and the value attributes are reserved keywords (the latter one by the second way of using attributes), they may not be used..."

    Thus, it would appear to be "expected" according to the documentation. I'm not entirely happy that this is a good idea though, considering "value" is an attribute of form elements.