Monday, April 16, 2012

Re: Issue with multiple select form input.

That is the proper name, because PHP sees that and creates an array with the values within that array. How else would you get multiple values for the same group?

When you submit the form, for example, the data is populated like this:

// $this->data
array(
  'Server' => array(
    'brand' => array('Dell', 'Apple')
  )
);

It sounds like the problem is that your search plugin is not expecting an array. Perhaps you can a) modify the plugin to accept an array, or b) modify how you pass the values in the URL to choose just the first one.

Just curious, how would you expect the URL to look to search for multiple brands?

On Monday, April 16, 2012 4:48:04 AM UTC-7, Owlio wrote:
Hi,

I hope someone can shed some light on this, it's driving me crazy. I have a multiple select list with options generated from a database. The problem is that the select name is being set, incorrectly, as follows:

name="data[Server][brand][]" 

When it should be:

name="data[Server][brand]"

This is causing problems as when an option is selected it displays in the URL as '.../brand[0]:Dell' which in turn throws of my search plugin as it's expecting '.../brand:Dell'. In my view the select box code is as follows:

echo $this->Form->create('Server', array('url' => array('action' => 'find'), $this->params['pass'])); 
   echo $this->Form->input('brand', array(
      'type' => 'select',
      'options' => $serverBrand,
      'multiple' => 'multiple',
));

With the options being generated in the controller, like so:

$serverBrand = Set::extract('/Server/brand', $this->Server->find('all', array(
   'fields' => array('DISTINCT Server.brand', 'Server.brand'),
   'recursive' => -1
)));
$serverBrand = array_combine($serverBrand, $serverBrand);
$this->set('serverBrand', $serverBrand);

The array_combine is necessary in order for the select box to insert the correct value in the URL, I've tried commenting this out but the above problem still persists. I need a way to either customize the select name, or preferably fix it. 

Any help would be greatly appreciated!

--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.
 
 
To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate