Defining default value in combobox in CakePHP
- by Keyur
<?php
echo $form->create('admin_merchant_form', array('action' => '#'));
echo $form->input('company_name', array('label' => 'Company Name'));
echo $form->input('ac_owner',
array('label' => 'Account Owner',
'options' => array('a','b','b'),
'default' => $merchant_select));
echo $form->end('Update');
?>
This is CakePHP code to generate a form with one combobox containing the values "a,b,c" and assigning the default value as $merchant_select which is numerical data. Now the problem is when I assign like 'default'=1 it returns 'b' in the combobox as default value but when writing 'default' = $merchant_select the combobox shows only the first value which is 'a'.
The $merchant_select variable is assigned a numeric value equal to merchant's id which 1,2 or 3 when I select any row in the grid. And I also have JavaScript code which alerts with the merchant value when I select any row in the grid so the numeric data is definitely assigned to the $merchant_select variable.