How do I implement an advanced combobox in CakePHP?
I have implemented a combobox in CakePHP using the following statement:
echo $form->select('brand_id',array($brands),null,array(),'Choose Brand');
For brand and category input form:
echo $form->input('category_id',array('type'=>'select',$categories,'empty'=>'Choose Category'));
But none of the above options allow me to add my text to a brand or category, for example, I want to add an entry that is not in the dropdown, how do I do it.
Like link in combobox or textbox in combobox?
There are 2 "other" fields:
echo $form->input('brand_other');
echo $form->input('category_other');
You will need 2 more fields in the database table for the model of this form, or logic in your controller that adds the values ββplaced in these "other" fields to your brand and category tables, and then adds the inserted ids to $this->data
brand_id
and category_id
before saving this model.
Also, you can use a method $form->input()
for both select boxes and you don't need to explicitly submit it $brands
or $categories
vars if available in your view, the form helper will detect this and automatically print the select box.
source to share