Page 1 of 1

[SOLVED]Returning Multiple Selected in Select control (Forms

Posted: Wed Jun 27, 2007 8:41 pm
by mevets
I have a option control that has multiple enabled:

Code: Select all

<SELECT name="lstfriends" multiple="yes" size=5>
<?php
$friendid = explode(',', $opt['friends']);
// parse friends
foreach ($friendid as $fid) {
	echo '<option>' . $fid . '</option>';
}
?>
</SELECT>
This creates a select control that has an option for each item in an array.

When this form is submitted I check $_POST['lstfriends'] with the print_r function. The problem is that I have multiple entries selected and it only returns the last of those selected. Is there another method used to return all the entries selected?

Posted: Wed Jun 27, 2007 9:45 pm
by feyd
Change the name to "lstfriends[]" PHP will create an array then.

Posted: Wed Jun 27, 2007 10:32 pm
by mevets
thanks, works