OK, this is basic PHP stuff really, but it’s something I don’t use very often so I thought I’d add a little note to remind myself.
HTML:
<form action="<?=$_SERVER['PHP_SELF']?>" method="post"> <select name="test[]" multiple="multiple"> <option value="one">one</option> <option value="two">two</option> <option value="three">three</option> <option value="four">four</option> <option value="five">five</option> </select> <input type="submit" value="Send" /> </form>
PHP:
<?php $test=$_POST['test']; if ($test){ foreach ($test as $t){echo 'You selected ',$t,'<br />';} } ?>
Source: http://onlinetools.org/tricks/using_multiple_select.php

May 10th, 2008 at 1:42 pm
Yeah, it’s quite handy - it works with checkboxes as well - just add in the square brackets to the name and php will treat them as an array:
May 10th, 2008 at 1:43 pm
Oh, this won’t let me post HTML - let’s try with some alpha entities…
<input type=”checkbox” name=”something[]” value=”one” />
<input type=”checkbox” name=”something[]” value=”two” />
<input type=”checkbox” name=”something[]” value=”three” />