【问题标题】:cakephp generates wrong label for radio input idcakephp 为无线电输入 id 生成错误的标签
【发布时间】:2013-12-04 21:54:49
【问题描述】:

当我在 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>

如您所见,蛋糕在标签上重复了表单名称“test”。我该如何解决这个问题?我尝试使用文档的确切代码,但仍然遇到同样的问题

希望你能帮助我,非常感谢

【问题讨论】:

    标签: php html cakephp radio-button


    【解决方案1】:

    我会自动回答我的问题。那是 cakephp 的一个错误,在上一个版本中解决了: https://github.com/cakephp/cakephp/releases/tag/2.4.2

    【讨论】:

    • 正要发帖说我看到这个问题在最近的版本中得到了修复,你应该更新你的 CakePHP 版本。
    【解决方案2】:

    尝试使用

    'label' => array(
            'class' => 'thingy',
            'text' => 'The User Alias'
        )
    

    【讨论】:

    • 这只是在标签中添加了这个:class="thingy" text="The User Alias",但“for”是相同的for="testTestOptionsOption1"
    猜你喜欢
    • 1970-01-01
    • 2016-03-30
    • 1970-01-01
    • 2020-05-10
    • 2013-05-12
    • 1970-01-01
    • 2015-06-24
    • 1970-01-01
    • 2010-10-12
    相关资源
    最近更新 更多