This is the code in my view:
echo $this->Form->create('Chart');
echo $this->Form->input('username',
array('label'=>('Usernames List'),
'empty'=>('Select username'),
'options'=>$usernames, 'selected'=>false));
echo $this->Form->input('month',
array('label'=>('Month'),
'empty'=>('Select month'),
'options'=>$months, 'selected'=>false));?>
echo $this->Form->input('year',
array('label'=>('Year'),
'empty'=>(date('Y')),
'options' => $years, 'selected'=>false));
echo $this->Form->end('Create Chart');
And in my controller I try to get the values from the above dropdownlists, this is my code:
if (!empty($this->data)) {
$username = $this->data['Chart']['username'];
$month = $this->data['Chart']['month'];
$year = $this->data['Chart']['year'];
}
But what I get in $username, $month and $year variables is the index of the element in the dropdownlist, instead of the value. For example if I select 2012 in Year droddownlist I get ‘0’, but what I need is ‘2012’.
How can I get the value?
Use array_combine (doc here)