Re: Issue with multiple select form input.

2012-04-17 Thread Owlio
>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?

Ahh! This makes perfect sense, to be honest, I'm not sure why I didn't 
realise this was the case.

>It sounds like the problem is that your search plugin is not expecting an 
array.

You were correct that the search plugin wasn't expecting an array (it was 
expecting a simple value) I've altered this now to unpack the values when 
they're passed through to my action and it works. I still have an issue 
when selecting multiple values as the URL is formed badly - but I should be 
able to resolve this.

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

Now I understand this, I'd expect them to be displayed like 
.../brand[0]:Dell/brand[1]:Apple/. Currently (now I've tweaked the plugin) 
the values are separated with a pipe, for example /brand:Dell%7CApple but 
as I mentioned above, this causes problems as the search plugin is taking 
the value literally which obviously returns no results.

Thanks for your help!



On Monday, April 16, 2012 11:38:45 PM UTC+1, jeremyharris wrote:
>
> 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+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php


Issue with multiple select form input.

2012-04-16 Thread Owlio
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+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php