views:

1642

answers:

1

Hi,

I have implemented combobox in cakephp using following statement -

echo $form->select('brand_id',array($brands),null,array(),'Choose Brand');

for brand and input form for category -

echo $form->input('category_id',array('type'=>'select',$categories,'empty'=>'Choose Category'));

but none of above option allows me to add my text input to brand or category, like say I want to add an input which is not there in the combobox, how should i go about it.

Like a link in the combobox or textbox in combobox?

-skr

A: 

Have 2 "other" fields:

echo $form->input('brand_other');
echo $form->input('category_other');

You'll either need 2 more fields in your database table for the model of this form, or logic in your controller that adds values posted in these "other" fields to your brands and categories tables, then add the inserted IDs to $this->data brand_id and category_id before saving this model.

Also, you can use the $form->input() method for both select boxes, and you don't need to explicitly send it $brands or $categories vars, if they are available in your view the form helper will detect this and print a select box automatically.

neilcrookes