Reputation: 11
I am new to CakePHP now I'm working on checkbox I used the following statement but it gives check box after the label and it prints the field also.My requirement is it does not print the field name and label should be displayed after the check box. please help me , Thanks in advance
<?php echo $form->input('Model.name', array('multiple' => 'checkbox', 'options' =>
$options, 'selected' => $selected));?>
Upvotes: 1
Views: 18874
Reputation: 51
CakePHP 3.0
$this->Form->input('id', ['type'=>'select', 'multiple' => 'checkbox', 'options'=>$array]);
Upvotes: 0
Reputation: 4776
To draw a check box you have to first configure your table in DB properly. Set these options on your field in DB:
and finally your view:
echo $this->Form->input('checkbox_field');
100% will work if not then set default value for your field in view:
echo $this->Form->input('checkbox_field', array('type'=>'checkbox'));
Upvotes: 0
Reputation: 1
My solution is according to v.2.0
<?php
echo $this->Form->input('field_name', array(
'label' => 'Some label',
'selected' => $selected
/*maybe some other options*/
));
?>
if you've specified model name above, while creating the form, you dont need to use name of model . If field is boolean, you'd get the control as checkbox automatically. Alsom you can specify it in options array like
'type'=>'checkbox'
good luck!
Upvotes: 0
Reputation: 8846
First, make sure your value is a boolean or tinyint. Otherwise, you will never get a checkbox.
Then, just build like this :
echo $this->Form->input('Model.field', array(
'type' => 'select',
'multiple' => 'checkbox',
'options' => array(
'Value 1' => 'Label 1',
'Value 2' => 'Label 2'
)
));
Upvotes: 13