Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Custom code to return all selected items from a dynamic list

Explorer ,
Sep 05, 2006 Sep 05, 2006
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.

TOPICS
Server side applications
706
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Explorer , Sep 07, 2006 Sep 07, 2006
Thanks to you both. I used the square brackets since they are in this season...

Lon
Translate
Guest
Sep 06, 2006 Sep 06, 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>";
}
?>
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 06, 2006 Sep 06, 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/
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Sep 06, 2006 Sep 06, 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>


Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 06, 2006 Sep 06, 2006
digitalus media wrote:
> 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?

I have just tested your in PHP 5.2.0RC3 on Apache 2.2.3. It doesn't
work. It generates a warning that bad arguments have been supplied to
implode(). Add the square brackets and it works perfectly.

Use var_dump($_POST); to inspect what is being sent. With the brackets
it's an array. Without the brackets, it's a string containing the last
selected element.

--
David Powers
Adobe Community Expert
Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
http://foundationphp.com/
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Sep 06, 2006 Sep 06, 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.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 06, 2006 Sep 06, 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/
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Sep 06, 2006 Sep 06, 2006
sure. thanks for the input.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Sep 07, 2006 Sep 07, 2006
LATEST
Thanks to you both. I used the square brackets since they are in this season...

Lon
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines