2
這個值是在我看來代碼:CakePHP的獲得從下拉列表
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');
在我控制我試圖從上述dropdownlists的價值觀,這是我的代碼:
if (!empty($this->data)) {
$username = $this->data['Chart']['username'];
$month = $this->data['Chart']['month'];
$year = $this->data['Chart']['year'];
}
但是,我在$ username,$ month和$ year變量中得到的是下拉列表中元素的索引,而不是值。例如,如果我在年份droddownlist中選擇2012,我會得到'0',但我需要'2012'。
我該如何獲得價值?
謝謝,它的工作原理! – myrmix 2012-03-23 15:50:10
謝謝! 這工作得很好。 – abbotto 2013-10-31 19:14:18