简体   繁体   English

如何编辑以zend形式选择的html属性?

[英]How to edit the html attribute selected in zend form?

So I'm working on a zend application version 1. 因此,我正在开发一个zend应用程序版本1。

I have my own custom form which generate this html : 我有自己的自定义表单,它会生成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 : 当我在提交后在我的控制器中检索ID时,我只得到该值的数据:

ie I retrieve 1 or 2 or 3 instead of B1 or B2 and so on and so forth. 即我检索1或2或3而不是B1或B2,依此类推。

$request->getParam("location");

How could I edit the attribute zend is selecting in select forms ? 我如何编辑zend在选择表单中选择的属性? 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. addMultiOptions()接受一个数组,并将其数组偏移量用作选项值,并将数组值用作选项的显示名称。

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);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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