ZF-2824: There is a serious need to change how Zend_Form handles populating multioption elements when creating form from config

Description

In current implementation when creating lets say SELECT element, we need to pass the options as 'val'=>'text', with that approache we face a problem when we want to assign integer value to option. With current zend_config we would need to have in XML something like <1>type11>, this is illegal in xml - so we cant assign integer values to options, and i think that is the most common use case for select elements ( database normalization for inserting values etc. ).

I would suggest we have something that could accept a format like

 
array(1) {
  ["multiOptions"]=>
  array(3) {
    [0]=>
    array(2) {
      ["val"]=>
      string(1) "1"
      ["key"]=>
      string(2) "aa"
    }
    [1]=>
    array(2) {
      ["key"]=>
      string(1) "2"
      ["val"]=>
      string(4) "xxxx"
    }
    [2]=>
    array(2) {
      ["val"]=>
      string(3) "444"
      ["key"]=>
      string(4) "ssss"
    }
  }
}

That way we can store our configuration in XML and generate options with text values as well.

Comments

Resolved in trunk and release-1.5 branch. You can now specify formats like the following in your config files:

  • INI

[testing]
options.first.key = "aa"
options.first.value = 1
options.second.value = "xxxx"
options.second.key = 2
options.third.key = "ssss"
options.third.value = 444
  • XML

<?xml version="1.0"?>
aa1xxxx2ssss444
  • PHP:

$options = array(
    array(
        'value' => '1',
        'key'   => 'aa',
    ),
    array (
        'key'   => '2',
        'value' => 'xxxx',
    ),
    array (
        'value' => '444',
        'key'   => 'ssss',
    ),
);

I would suggest reopening this issue for the following reason: Short-hand xml configuration does not work.

1Male

Generates this (formatted for readability):


    
    Male


    
    Female