在Cakephp中创建单选按钮的表单助手

时间:2009-09-07 11:08:24

标签: cakephp

我正在尝试使用Cakephp创建一个单选按钮,结果类似于

         <div data-attr="radio" id="1">
          <label id="label1">Untitled1</label><br/>

          <input type="radio" value="option1" id="Radio11" name="Workexperience"/>
          <label for="Radio11">Option1</label>
         <input type="radio" value="option2" id="Radio12" name="Workexperience"/>
         <label for="Radio12">Option2</label>

        </div>

如何使用Form helper生成如此... 请建议我..

2 个答案:

答案 0 :(得分:12)

这可能会有所帮助,

http://book.cakephp.org/view/189/Automagic-Form-Elements#options-before-options-between-options-separator-a-191

对于无线电类型输入,'separator'属性可用于注入标记以分隔每个输入/标签对。

代码视图

<?php echo $form->input('field', array(
    'before' => '--before--',
    'after' => '--after--',
    'between' => '--between---',
    'separator' => '--separator--',
    'options' => array('1', '2'),
    'type' => 'radio'
));?>

输出:

<div class="input">
--before--
    <input name="data[User][field]" type="radio" value="1" id="UserField1" />
    <label for="UserField1">1</label>
--separator--
    <input name="data[User][field]" type="radio" value="2" id="UserField2" />
    <label for="UserField2">2</label>
--between---
--after--
</div>

答案 1 :(得分:1)

看起来$form->radio()应该做你需要的。我不知道它是否与你的例子完全一样。