I'm creating multi checkbox and allow user to check them but in controller when I need to retrieve question_id and multi responses id, i get only single response id.
structure of data is following
$options = array(
array('6'=>'food','rsponses' => array('id' => 1, 'name' => 'asian'),array('id'=>'2', 'name'=>'european'),array('id'=>'3', 'name'=>'chinees') ),
array('8'=>'hobbies' ,'responses' => array('id' => 1, 'name' => 'cricket'),array('id'=>'2', 'name'=>'reading'),array('id'=>'3', 'name'=>'watching TV') )
);
Structure given below after debug easy to understand. In this 'food', 'hobbies' are question , i need id of these question and responses id against each question to save in database user response for each question. can you please give me any hint how to do this one.
[
(int) 0 => [
(int) 6 => 'food',
'rsponses' => [
'id' => (int) 1,
'name' => 'asian'
],
(int) 7 => [
'id' => '2',
'name' => 'european'
],
(int) 8 => [
'id' => '3',
'name' => 'chinees'
]
],
(int) 1 => [
(int) 8 => 'hobbies',
'responses' => [
'id' => (int) 1,
'name' => 'cricket'
],
(int) 9 => [
'id' => '2',
'name' => 'reading'
],
(int) 10 => [
'id' => '3',
'name' => 'watching TV'
]
]
]
To display question and checkbox for user, I'm unig this code
foreach ($options as $responses => $responsesOptions) {
$legend = $this->Html->tag('legend', $responses);
$checkboxes = $this->Form->select($responses, $responsesOptions, [
'name' => 'field',
'multiple' => 'checkbox'
]);
echo $this->Html->tag('fieldset', $legend . $checkboxes);
}
Aucun commentaire:
Enregistrer un commentaire