Reputation: 71
I have a Drop down List consisting of 3 values(pending,delivered,processing). I have to set the default value as the one from the database.The default value should be the status corresponding to the particular order in the database.so can you please suggest the query to set the default value in the drop down list.
echo $this->Form->input('status', array(
'empty'=>$r,
'options' => array(
'pending' =>'pending',
'delivered' => 'delivered',
'processing' => 'processing')
));
here $r contains the value of the status fetched from database
Upvotes: 2
Views: 3411
Reputation: 4177
If you want to set $r
as selected value in the dropdown then you can proceed like this.
echo $this->Form->input('status', array(
'default' => $r, // since your default value is $r
'options' => array(
'pending' =>'pending',
'delivered' => 'delivered',
'processing' => 'processing')
));
(OR)
this can also possible by setting value
attribute of your options array.
i.e.
echo $this->Form->input('status', array(
'selected' => $r,
'options' => array(
'pending' =>'pending',
'delivered' => 'delivered',
'processing' => 'processing')
));
Hope this will help you.
Upvotes: 3