cakephp - How can one set selected options for a cake php FormHelper multiple select? -


the template form element be:

$ingredientoptions = array('potato','peanut','parsley'); echo $this->form->input('favouriteingredients', array('multiple' => true, 'options' => $ingredientoptions); echo $this->form->input('allergicingredients', array('multiple' => true, 'options' => $ingredientoptions); 

this creates 2 (ugly) multiple select boxes, each list consisting of elements options array, none of selected.

to set initial values, i've tried few things in controller without success:

$this->set('favouriteingredients',array(1,2)); $this->request->data['favouriteingredients'] = array(1,2); 

these multiple selects 2 habtm relationships defined in customer model:

class customer extends appmodel {     public $hasandbelongstomany = array(         'favouriteingredients' =>               array(                 'classname' => 'ingredient',                 'jointable' => 'customer_ingredients_favourite'             );          'allergicingredients' =>             array(                 'classname' => 'ingredient',                 'jointable' => 'customer_ingredients_allergic'             );      ); } 

actually problem in production values didn't exist in options array. works:

$this->request->data['customer']['favouriteingredients'] = array(1,2); 

Comments

Popular posts from this blog

dns - How To Use Custom Nameserver On Free Cloudflare? -

python - Pygame screen.blit not working -

c# - Web API response xml language -