Reputation: 1133
I have a form for creating a task, and when creating it, user is asked to select which employees will be assigned to it. There may be just one employee or even up to 10. I allow user to dynamically create those input fields on the go, but the array that i get after the form submition looks like this:
array(
'Event' => array(
'project_id' => '62',
'user_id' => '23',
'user_id2' => '24',
'user_id4' => '28',
'user_id8' => '30',
'hours' => '6',
'minutes' => '0',
'assignment' => '',
'material' => 'safsaf',
'date' => '2013-10-12',
)
)
The problem is I do not know how to iterate over the user_ids. Is it possible to save the IDs as a list? Or is there any other solution?
Upvotes: 0
Views: 106
Reputation: 29121
Use CakePHP's find('list') to retrieve the $users in an key=>value
array, then set the multiple
attribute of the input to true:
echo $this->Form->select('Model.field', $users, array('multiple' => true));
$attributes['multiple'] If ‘multiple’ has been set to true for an input that outputs a select, the select will allow multiple selections:
Upvotes: 1