<select multiple> and /return/ multiple variables...?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Skara
Forum Regular
Posts: 703
Joined: Sat Mar 12, 2005 7:13 pm
Location: US

<select multiple> and /return/ multiple variables...?

Post by Skara »

Ok... I'm kinda confused.
I need a good way to select multiple categories and when they're submitted, parse them. I plan on having a few dozen categories, so checkboxes would be cumbersome to say the least.
Now I thought that a <select multiple> tag would let me actually return more than one answer, but hell if I can figure out how.

Erhm... in other words, I need something like this:

Code: Select all

<select multiple='multiple' name='cats'>
<option>one</option>
<option>two</option>
<option>three</option>
</select>
Where I can actually select more than one option and it will actually return more than one option.

As it stands, the above will only return the highest--lowest in the code--option selected.

What am I missing?

Edit: It works fine in $_GET, but not $_POST, which is most certainly what I'm going to need. :/
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

you need to make the select an array:

ex:

Code: Select all

<select multiple="multiple" name="cats[]"> 
<option value="one">one</option> 
<option value="two">two</option> 
<option value="three">three</option> 
</select>
then handle the array on the other side...
User avatar
Skara
Forum Regular
Posts: 703
Joined: Sat Mar 12, 2005 7:13 pm
Location: US

Post by Skara »

voila, problem solved. Thanks.

I'm already using an array, so that makes yet another 2d array to parse. ^^;
Post Reply