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

use*_*non 3 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>
Run Code Online (Sandbox Code Playgroud)

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

Ana*_*hah 12

这可能有所帮助,

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

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

代码视图

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

输出:

<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>
Run Code Online (Sandbox Code Playgroud)

  • +1.为什么这个家伙被投票?他花时间回答问题而你从他那里得分?如果FormHelper :: input()不够灵活,请使用FormHelper :: radio().如果这不够灵活,请手动编写您需要的HTML.http://api.cakephp.org/class/form-helper#method-FormHelperradio (4认同)