Am 04.11.2011, 11:52 Uhr, schrieb Fred Garlov <[email protected]>:

Hello,

is there a way to render a multi select element not as array?

        $element = new \Zend_Form_Element_Multiselect('myname');
        $element->setMultiOptions($names);


which renders

<select name="myname[]" multiple="multiple">
    <option value="o1" label="L 1">L 1</option>
    <option value="o2" label="L 2">L 2</option>
</select>


As one can see, "myname[]" has brackets now, which is not desired in my case.

The brackets are needed!

Here is an example:

(CODE)

<select name="foo[]" multiple="multiple">
    <option value="o1" label="L 1">L 1</option>
    <option value="o2" label="L 2">L 2</option>
</select>
<select name="bar" multiple="multiple">
    <option value="o1" label="L 1">L 1</option>
    <option value="o2" label="L 2">L 2</option>
</select>

if (count($_POST)) {
    // Foo
    echo 'Foo: ';
    echo gettype($_POST['foo']);
    echo '<br>';

    print_r($_POST['foo']);

    // Bar
    echo 'Bar: ';
    echo gettype($_POST['bar']);
    echo '<br>';

    print_r($_POST['bar']);
}

(OUTPUT)

Foo: array
Array ( [0] => o1 [1] => o2 )

Bar: string
o2

--
List: [email protected]
Info: http://framework.zend.com/archives
Unsubscribe: [email protected]


Reply via email to