0
votes

I am using jQuery and CakePHP for my application.

In my application with the data that I have saved in the database, for example if the Field type column is text then I am generating a text box in my code using $form->input();

If it is a dropdown box, I am generating it using:

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

Now I have a field of type "Radio button". I am trying to create the radio box in CakePHP. Is it possible... If so how?

3

3 Answers

4
votes

Using FormHelper::input(), you can specify the type of field you want by setting the type option:

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

Unlike calling FormHelper::radio() directly, the input's label and validation errors will be rendered.

1
votes

For example:

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

Try with your attributes

0
votes
    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')
    ));