Cakephp单选按钮与标签

时间:2014-05-22 01:59:18

标签: html forms cakephp

我需要创建以下html代码才能使用bootstap

<div class="input-group">
    <span class="input-group-addon">
        <input type="radio">
    </span>
    <input type="text" class="form-control">
</div>

所以我需要单个单选按钮,没有任何标签和图例。我只是尝试如下。

echo $this->Form->radio('Answer.0.correct', array(
    'value' => 1,   
));

它生成了以下html

<input type="hidden" value="" id="Answer0Correct_" name="data[Answer][0][correct]">
<input type="radio" value="value" id="Answer0CorrectValue" name="data[Answer][0][correct]">
<label for="Answer0CorrectValue">1</label>

我将label选项设置为false。

echo $this->Form->radio('Answer.0.correct', array(
    'value' => 1,   
    'label' => false,
));

但是它已经用fieldset创建了不需要的无线电。

<fieldset>
    <legend>Correct</legend>
    <input type="hidden" value="" id="Answer0Correct_" name="data[Answer][0][correct]">
    <input type="radio" value="value" id="Answer0CorrectValue" name="data[Answer][0][correct]">
    <label for="Answer0CorrectValue">1</label>
    <input type="radio" value="label" id="Answer0CorrectLabel" name="data[Answer][0][correct]">
    <label for="Answer0CorrectLabel"></label>
</fieldset>

如何创建单个单选按钮(带有隐藏字段)?

3 个答案:

答案 0 :(得分:2)

more info

$options = array('1' => false, '2' => false);
$attributes = array('legend' => false, 'label' => false);
echo $this->Form->radio('gender', $options, $attributes);

答案 1 :(得分:0)

试试这个: -

$attributes = array('1' =>false);
echo $this->Form->radio('Answer.0.correct', $attributes);

答案 2 :(得分:-1)

如果无法使用Form Helper生成所需的输出,您仍然可以在视图文件中编写HTML代码。所以在你的index.ctp或* .ctp中只需输入

<div class="input-group">
   <span class="input-group-addon">
      <input type="radio">
   </span>
   <input type="text" class="form-control">
</div>

你们都已经准备好了。我不明白为什么你必须使用Form Helper生成这个标记。