PDA

View Full Version : How to get values from a multiple select list web interface ?



erland
2006-03-25, 04:28
Does anyone know how to retreive values in the perl code from a multiple select list in the web interface ?

The input field in the form in the web interface look like this:
<select name="artistList" multiple size="10">
<option value="1">Artist1</option>
<option value="2">Artist2</option>
<option value="3">Artist3</option>
</select>

In the perl code it looks like this:
sub handleWebGenerateNewPlaylist {
my ($client, $params) = @_;

my @artists = $param->{artistList};
}

The problem is that artistList does not seem to be an array, instead the "artists" I will just be single string containing 1 or 2 or 3, but never more than one value even though I have selected several values in the list.

Is there anyone that knows how to solve this ?

mherger
2006-03-25, 09:39
> my @artists = $param->{artistList};

have you tried something like

my @artists = ($param->{artistList1}, $param->{artistList2});

--

Michael

-----------------------------------------------------------
Help translate SlimServer by using the
StringEditor Plugin (http://www.herger.net/slim/)

erland
2006-03-26, 00:08
It does not work, the params variable contains the following:
LOCALE = utf-8
content =
player = 97:d9:97:e4:bb:a7
path = plugins/SQLPlayList/sqlplaylist_generatenewplaylist.html
url_query = type=includingartists&artistList=11&artistList=4
host = inspiron8600lin:9000
Content-Type = text/html
type = includingartists
artistList = 4
webroot = /
playermodel = squeezebox
pluginSQLPlayListVersion = 6.5b1
myClientState = Slim::Player::SoftSqueeze=ARRAY(0xa594ebc)

So the result when 4 and 11 is selected in the list is:
$params->{"artistList[1]"}: Returns nothing
$params->{"artistList1"}: Returns nothing
$params->{"artistList.1"}: Returns nothing
$params->{"artistList"}: Returns "4" in the example above, so it returns only one of the selected items.

I can parse url_query but I feel that there has to be a better way. According to other perl pages on the net it seems like I should be able to get an array back with $params->{"artistList"}, but this does not seem to be the case in slimserver.

Any help or ideas is appreciated.

Grotus
2006-03-26, 11:14
erland blurted out:
> It does not work, the params variable contains the following:
> LOCALE = utf-8
> content =
> player = 97:d9:97:e4:bb:a7
> path = plugins/SQLPlayList/sqlplaylist_generatenewplaylist.html
> url_query = type=includingartists&artistList=11&artistList=4
> host = inspiron8600lin:9000
> Content-Type = text/html
> type = includingartists
> artistList = 4
> webroot = /
> playermodel = squeezebox
> pluginSQLPlayListVersion = 6.5b1
> myClientState = Slim::Player::SoftSqueeze=ARRAY(0xa594ebc)
>
> I can parse url_query but I feel that there has to be a better way.

Sorry, but no, there is currently no better way. Look in
Slim::Web::HTTP::processHTTP() around the comment # parse out URI.

We overwrite previous query values with the later ones, which is why
artistList contains only the last value sent. I'm not sure if this
behavior is expected anywhere.

According to the comment around there we also have some queries coming
in like page.html?key1&key2=&key3=x and that we want to treat the key1
key as if it had been key1=1 rather than like key2 where the value is
just empty. I'm not sure where this comes into play.

If we can establish that we no longer need those two behaviors, we could
switch to using URI::QueryParam, specifically $uri->query_param_hash()
to load up our param hash with values. QueryParam would take a repeated
key like you see in your example and turn the value into an array ref.

erland
2006-03-26, 21:56
Thanks

Now I know why it does not work, I guess I'll just have to parse the url_query parameter for now.