当我在CakePHP上使用无线电输入创建表单时,生成的标签与无线电输入的ID不匹配,标签“for”复制表单的名称。这是我的代码:
echo $this->Form->create(
'test',
array(
'action' => 'index',
'type' => 'post',
'class' => 'fill-up',
'inputDefaults' => array('div' => 'input')));
$options = array('option1' => '1',
'option2' => '2');
$attributes = array('legend' = > false);
echo $this->Form->radio('Type', $options, $attributes);
echo $this->Form->end(
array(
'label' = > 'end',
'class' = > 'button',
'div' = > false));
生成的HTML类似于:
<input type="hidden" name="data[test][options]" id="testOptions_" value="">
<input type="radio" name="data[test][options]" id="TestOptionsOption1" value="option1">
<label for="testTestOptionsOption1">1</label>
<input type="radio" name="data[test][options]" id="TestOptionsOption2" value="option2">
<label for="testTestOptionsOption2">2</label>
如您所见,cake在标签上复制了表单名称“test”。我怎么解决这个问题?我尝试使用文档的确切代码,仍然有相同的问题
希望你能帮助我,非常感谢
答案 0 :(得分:1)
我自动回答了我的问题。那是cakephp的一个bug,在最后一个版本上解决了: https://github.com/cakephp/cakephp/releases/tag/2.4.2
答案 1 :(得分:0)
尝试使用
'label' => array(
'class' => 'thingy',
'text' => 'The User Alias'
)