Jump to content

Archived

This topic is now archived and is closed to further replies.

mojito

multiple select reading

Recommended Posts

Hi freaks

Im comming back into some form problems, i thought a multiple select form sent a comma separated values but when using and selecting multiple options the query string is like

select=me&select=too&Submit=Submit

do i have to iterate through each select and make an array myself?

thanks

mojito

Share this post


Link to post
Share on other sites
Try HTML: <select multiple name="myselectbox[]"> ... </select>

XHTML: <select multiple="multiple" name="myselectbox[]"> ... </select>


PHP:

$selections = $_GET['myselectbox']; // or $_POST

for ($i = 0, $cnt = count($selections); $i < $cnt; $i++) {

echo 'You selected: ', $selections[$i], '<br/>';

}

or:

$selections = $_GET['myselectbox']; // or $_POST

foreach ($selections as $choice) {

echo 'You selected: ', $choice, '<br/>';

}


Edit: Forgot "multiple" so I added it - thx kenrbnsn. I'm sure mojito has mutiple already specified since his post shows he's getting: select=me&select=too

Share this post


Link to post
Share on other sites
Please post the souce for your form.

You need to make the name of the select list an array.
[code]<select name="select[]" multiple>[/code]

Ken

Share this post


Link to post
Share on other sites
[!--quoteo(post=374714:date=May 17 2006, 04:31 PM:name=kenrbnsn)--][div class=\'quotetop\']QUOTE(kenrbnsn @ May 17 2006, 04:31 PM) [snapback]374714[/snapback][/div][div class=\'quotemain\'][!--quotec--]
Please post the souce for your form.

You need to make the name of the select list an array.
[code]<select name="select[]" multiple>[/code]

Ken
[/quote]

yer i tried that and the result is

select%5B%5D=me&select%5B%5D=too&Submit=Submit

so its just encoding the brackets, and not making an array.
here is my source
[code]<select name="select[]" size="2" multiple="multiple">
    <option value="me">1</option>
    <option value="too">2</option>
  </select>[/code]

m

Share this post


Link to post
Share on other sites
[!--quoteo(post=374788:date=May 17 2006, 02:24 PM:name=mojito)--][div class=\'quotetop\']QUOTE(mojito @ May 17 2006, 02:24 PM) [snapback]374788[/snapback][/div][div class=\'quotemain\'][!--quotec--]
yer i tried that and the result is

select%5B%5D=me&select%5B%5D=too&Submit=Submit

so its just encoding the brackets, and not making an array.

m
[/quote]
it will be an array if you try
[code]print_r($_GET['select']);[/code]

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.