$ form->输入以使用CakePHP创建单选按钮

时间:2009-09-07 10:04:57

标签: cakephp

我正在为我的应用程序使用jQuery和CakePHP。

在我的应用程序中使用我保存在数据库中的数据,例如,如果字段类型列是文本,那么我在代码中使用$ form-> input()生成一个文本框;

如果是下拉框,我将使用以下方式生成它:

echo $form->input($r['Attribute']['label'],
    array('id'=>$r['Attribute']['id'],'name'=>$r['Attribute']['label'],
        'options' => array(1,2,3,4,5))); 

现在我有一个“单选按钮”类型的字段。我正在尝试在CakePHP中创建无线电盒。 是否可能......如果是这样的话?

3 个答案:

答案 0 :(得分:4)

使用FormHelper::input(),您可以通过设置type选项指定所需的字段类型:

echo $form->input($r['Attribute']['label'], array(
    'type' => 'radio',
    'id' => $r['Attribute']['id'],
    'name' => $r['Attribute']['label'],
    'options' => array(1, 2, 3, 4, 5),
));

与直接调用FormHelper::radio()不同,将呈现输入的标签和验证错误。

答案 1 :(得分:1)

例如:

$options=array('M'=>'Male','F'=>'Female');
$attributes=array('legend'=>false);
echo $this->Form->radio('gender',$options,$attributes);

尝试使用您的属性

答案 2 :(得分:0)

    echo $form->input($r['Attribute']['label'],
    array('id'=>$r['Attribute']['id'],'name'=>$r['Attribute']['label'],
         'type'=>'radio',
         'options' => array(1=>'male',2=>'female',3=>'Others')
    ));
相关问题