2009-07-01 158 views
7

分组单选按钮,我想提出在逻辑产品组单选按钮:Zend框架

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/> 

不知道确切的格式代码。只有形式要素很重要。

+3

这听起来像它可能是同样的问题。 http://framework.zend.com/issues/browse/ZF-3541 报告提出了一个修复他的帖子。 – 2009-07-01 16:25:37

+0

你在使用Zend_Form吗? – jason 2009-07-07 04:05:33

+0

是的,我确实使用Zend_Form。 – 2009-07-07 08:46:16

回答

12

你是正确的,ZF 1.8不支持以这种方式对选项进行分组。您可以轻松查看Zend_View_Helper_FormRadio中的代码并创建您自己的支持多维数组(即选择分组)的视图助手。我不得不为一个项目已经这样做了,在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'), 
    ), 
)); 

生成的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>