derRobert
derRobert

Reputation: 571

Optgroup in Zend Form defined by ini

How do i specify optgroups in Zend_Form (1.x), when the form itself is constructed by an ini-file?

I'd like to list a number of airports "grouped" by country

France
  - Paris
Germany
  - Munich
  - Hamburg
Spain
  - Madrid
  - Barcelona

ini:

elements.airports.type = "select"
elements.airports.options.label = "Airport:"
elements.airports.options.multiOptions... ???

Upvotes: 0

Views: 127

Answers (1)

yearofthetiger
yearofthetiger

Reputation: 56

Check out the class Zend_Form_Element_Multi, in the isValid method, it mentions optgroup.

foreach ($multiOptions as $opt_value => $opt_label) {
    // optgroup instead of option label
   if (is_array($opt_label)) {
      $options = array_merge($options, array_keys($opt_label));
   }
...

So, the optGroups are an array of options. In your example:

elements.airports.options.multiOptions.optGroupName.optionValue = "optionText"
elements.airports.options.multiOptions.France.PA = Paris
elements.airports.options.multiOptions.Germany.MU = Munich
elements.airports.options.multiOptions.Germany.HA = Hamburg

Upvotes: 1

Related Questions