mojito Posted May 17, 2006 Share Posted May 17, 2006 Hi freaksIm 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 likeselect=me&select=too&Submit=Submitdo i have to iterate through each select and make an array myself?thanksmojito Quote Link to comment https://forums.phpfreaks.com/topic/9865-multiple-select-reading/ Share on other sites More sharing options...
toplay Posted May 17, 2006 Share Posted May 17, 2006 Try HTML: <select multiple name="myselectbox[]"> ... </select>XHTML: <select multiple="multiple" name="myselectbox[]"> ... </select>PHP:$selections = $_GET['myselectbox']; // or $_POSTfor ($i = 0, $cnt = count($selections); $i < $cnt; $i++) { echo 'You selected: ', $selections[$i], '<br/>';}or:$selections = $_GET['myselectbox']; // or $_POSTforeach ($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 Quote Link to comment https://forums.phpfreaks.com/topic/9865-multiple-select-reading/#findComment-36658 Share on other sites More sharing options...
kenrbnsn Posted May 17, 2006 Share Posted May 17, 2006 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 Link to comment https://forums.phpfreaks.com/topic/9865-multiple-select-reading/#findComment-36659 Share on other sites More sharing options...
mojito Posted May 17, 2006 Author Share Posted May 17, 2006 [!--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=Submitso 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 Quote Link to comment https://forums.phpfreaks.com/topic/9865-multiple-select-reading/#findComment-36732 Share on other sites More sharing options...
ryanlwh Posted May 17, 2006 Share Posted May 17, 2006 [!--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=Submitso 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] Quote Link to comment https://forums.phpfreaks.com/topic/9865-multiple-select-reading/#findComment-36735 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.