7

我想在逻辑产品组中显示单选按钮:

Broadband products:
  (*) 2 Mbit
  ( ) 4 Mbit

Voice products:
  ( ) Standard
  ( ) Total

Bundles:
  ( ) 4 Mbit + Standard
  ( ) 4 Mbit + Total

所有单选按钮都具有相同的name属性 - 你明白了。Zend Framework 1.8 似乎不支持以这种方式对单选按钮进行分组。有什么解决办法吗?

更新。澄清一下,生成的代码看起来应该是这样的:

Broadband products: <br/>
<input type="radio" name="product" value="1"/> 2 Mbit <br/>
<input type="radio" name="product" value="2"/> 4 Mbit <br/>

Voice products: <br/>
<input type="radio" name="product" value="3"/> Standard <br/>
<input type="radio" name="product" value="4"/> Total <br/>

Bundels: <br/>
<input type="radio" name="product" value="5"/> 4 Mbit + Standard <br/>
<input type="radio" name="product" value="6"/> 4 Mbit + Total <br/>

没关系确切的格式代码。只有表单元素很重要。

4

2 回答 2

12

You're correct that ZF 1.8 doesn't support grouping of options in this way. You could easily look at the code inside Zend_View_Helper_FormRadio and create your own view helper that supports a multi-dimensional array (ie the select groupings). I had to do this already for a project, check out the example at pastebin.com

PHP:

$form->addElement('radio', 'test', array(
    'helper'=>'formMultiRadio',
    'label'=>'Test Thing',
    'multiOptions'=>array(
        'Test'=>array('1'=>'1', '2'=>'2'),
        'Test 2'=>array('3'=>'3', '4'=>'4'),
        'Test 3'=>array('5'=>'5', '6'=>'6'),
      ),
  ));

Resulting HTML:

<dt id="test-label"><label for="test" class="optional">Test Thing</label></dt>

<dd id="test-element">
Test<br />
<label for="test-1"><input type="radio" name="test" id="test-1" value="1" />1</label><br />
<label for="test-2"><input type="radio" name="test" id="test-2" value="2" />2</label><br />
Test 2<br />
<label for="test-3"><input type="radio" name="test" id="test-3" value="3" />3</label><br />
<label for="test-4"><input type="radio" name="test" id="test-4" value="4" />4</label><br />
 Test 3<br />
 <label for="test-5"><input type="radio" name="test" id="test-5" value="5" />5</label><br />
 <label for="test-6"><input type="radio" name="test" id="test-6" value="6" />6</label>
 </dd>
于 2009-07-09T01:11:28.637 回答
0

看看 Zend_Form_Element_Radio

http://framework.zend.com/manual/en/zend.form.standardElements.html#zend.form.standardElements.radio

还有多复选框类,但我想它只适用于复选框 http://framework.zend.com/manual/en/zend.form.standardElements.html#zend.form.standardElements.multiCheckbox

于 2009-07-03T18:50:44.967 回答