简体   繁体   中英

How to edit the html attribute selected in zend form?

So I'm working on a zend application version 1.

I have my own custom form which generate this html :

<select name="location" id="location" class="span6">
    <option value="1" label="B1">B1</option>
    <option value="2" label="B2">B2</option>
    <option value="3" label="B3">B3</option>
    <option value="4" label="B4">B4</option>
    <option value="5" label="B5">B5</option>
    <option value="6" label="B6">B6</option>
    <option value="7" label="B7">B7</option>
    <option value="8" label="B8">B8</option>
    <option value="9" label="B9">B9</option>
    <option value="10" label="B10">B10</option>
</select>

And when I retrieve the id in my controller after the submit I only get the data of the value :

ie I retrieve 1 or 2 or 3 instead of B1 or B2 and so on and so forth.

$request->getParam("location");

How could I edit the attribute zend is selecting in select forms ? Or how can I populate the dropdown with my value ?

This how I create the dropdown :

$formSell->location->addMultiOptions($config->location->toArray());

Some help would be nice :) Thanks

addMultiOptions() takes an array and uses it's array offset as the option value, and the array value as the display name of the option.

To get what you want, you just need to adjust your array. Consider the following;

$arrOutput = array();

$arrRawData = $config->location->toArray();

foreach( $arrRawData as $row ) {

    $arrOutput[$row] = $row;

}

$formSell->location->addMultiOptions($arrOutput);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM