Iv got a problem with a multiple select form

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
AshrakTheWhite
Forum Commoner
Posts: 69
Joined: Thu Feb 02, 2006 6:47 am

Iv got a problem with a multiple select form

Post by AshrakTheWhite »

Hey good day chaps :)

Can anyone explaine to me how to make a multy select form return the selected option ID's or whatever to diferentiate them from eachother aka if i select o1 and o4 the POST would return me those values

Code: Select all

<SELECT MULTIPLE SIZE=5>
 <OPTION VALUE="o1">Option 1
 <OPTION VALUE="o2">Option 2
 <OPTION VALUE="o3">Option 3
 <OPTION VALUE="o4">Option 4
 <OPTION VALUE="o5">Option 5
 <OPTION VALUE="o6">Option 6
</SELECT>
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post by shiznatix »

first, you gotta give it a name. second you gotta make the name an array, because you will want an array from that name. third, use the multiple="multiple" as the other way is depreciated or somthin. this works:

Code: Select all

<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>
jeeep
Forum Commoner
Posts: 57
Joined: Fri Apr 28, 2006 1:43 am

Post by jeeep »

I'm having somewhat the same problem. Can I do this to this:

Code: Select all

<select name="test[]" multiple="multiple">
   <option value="/teamspeakimg.png">Image1</option>
   <option value="/teamspeakimg2.png">Image2</option>
   
</select>
to select a pic. for this php file

Code: Select all

$test = $_POST['test'];
$test=array();
$image1=$test[];
(Not really sure how to do it properly in the php file)
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

A great way to "look" at what is being posted is to put this code in the page you are posting to. Look at what is being posted and play around with it.

Code: Select all

echo '<pre>';
print_r($_POST);
echo '</pre>';
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

jeeep wrote:I'm having somewhat the same problem. Can I do this to this:

Code: Select all

<select name="test[]" multiple="multiple">
   <option value="/teamspeakimg.png">Image1</option>
   <option value="/teamspeakimg2.png">Image2</option>
   
</select>
to select a pic. for this php file

Code: Select all

$test = $_POST['test'];
$test=array();
$image1=$test[];
(Not really sure how to do it properly in the php file)
Like this

Code: Select all

$images = $_POST['test'];
foreach($images as $temp)
{
    echo $temp;
}
jeeep
Forum Commoner
Posts: 57
Joined: Fri Apr 28, 2006 1:43 am

Post by jeeep »

awesome ty!
Post Reply