Skip to main content
Inspiring
September 6, 2006
Answered

Custom code to return all selected items from a dynamic list

  • September 6, 2006
  • 4 replies
  • 704 views
Does anyone know of custom code to return all selected items from a dynamic list? Support tells me that Dreamweaver only returns the last item. If any one can give me any hints how to do this custom code or can point me to some code, I would be eternally grateful.

This topic has been closed for replies.
Correct answer Rankin
Thanks to you both. I used the square brackets since they are in this season...

Lon

4 replies

Inspiring
September 6, 2006
digitalus media wrote:
> it is odd that it is working on my server. i wish i could figure out why. little things like that can make migrating from the testing server to production a real pain.

It certainly is odd. I have never encountered a situation where it works
without the addition of the square brackets. I would advise adding them
in, as it's the correct syntax:

http://www.php.net/manual/en/faq.html.php#faq.html.arrays

--
David Powers
Adobe Community Expert
Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
http://foundationphp.com/
September 6, 2006
sure. thanks for the input.
RankinAuthorCorrect answer
Inspiring
September 8, 2006
Thanks to you both. I used the square brackets since they are in this season...

Lon
September 6, 2006
it is odd that it is working on my server. i wish i could figure out why. little things like that can make migrating from the testing server to production a real pain.
Inspiring
September 6, 2006
digitalus media wrote:
> When you have a multiselect list the form sends an array of the selected items.

This needs to be clarified. The form will only send an array if the name
attribute of the <select> element is followed by an empty pair of square
brackets like this:

<select name="multiSelect[]" multiple="multiple" size="6">

If you omit the square brackets, the form submits only the last selected
item.

You need to use the square bracket notation with all form elements that
permits the selection of multiple values, so this is needed for check
boxes, too, unless you give each check box a different name.

--
David Powers
Adobe Community Expert
Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
http://foundationphp.com/
September 6, 2006
Hi David,
I thought that was the case as well, but I tried it with and without the brackets (on my local server, wamp: php 5.1.4, apache 2) and it worked both ways. Is this a server configuration issue?

<?php
if(isset($_POST['Submit'])){echo "Selected items: ".(implode(', ',$_POST['select']));}
?>

<form id="form1" name="form1" method="post" action="index.php">
<label>
<select name="select" size="4" multiple="multiple">
<option>one</option>
<option>two</option>
<option>three</option>
<option>four</option>
</select>
</label>
<p>
<label>
<input type="submit" name="Submit" value="Submit" />
</label>
</p>
</form>


September 6, 2006
When you have a multiselect list the form sends an array of the selected items.

if you just want to display them you can use the implode function:
<?php echo "Selected items: ".(implode(', ',$_POST['select']));?>

if you want to do something with them then use foreach:
<?php
foreach($_POST['select'] as $item){
echo "<p>Item:".$item."</p>";
}
?>