Web Design - Web Applications - Internet Marketing
  FAQHome   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister    ProfileProfile   Private messagesPrivate messages   Log inLog in

PHP Multiple Select

 
Post new topic   Reply to topic    SharkZone Design Forum Index -> CGI, Perl, PHP, and SSI scripting
View previous topic :: View next topic  
Author Message
JonnHalzmans



Joined: 14 Apr 2007
Posts: 1
Location: USA

PostPosted: Wed Oct 31, 2007 2:14 pm    Post subject: PHP Multiple Select Reply with quote

When I create a HTML multiple select box the return value in PHP is only a single item not an array as I would expect.
Back to top
View user's profile Send private message
SharkZoneDesign



Joined: 17 Mar 2007
Posts: 15
Location: Phoenix, Arizona

PostPosted: Wed Oct 31, 2007 3:08 pm    Post subject: Re: PHP Multiple Select Reply with quote

JonnHalzmans wrote:
When I create a multiple select box the return value in php is only a single item not an array as I would expect.


In order to get an array back from the multiple select box in PHP, you have to put array brackets at the end of the select box name. If you don’t, PHP will only populate the $_POST entry with the last element selected.

HTML
Code:

<form action="<?=$_SERVER['PHP_SELF']?>" method="post">
<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>
<input type="submit" value="Send" />
</form>


PHP

Code:

<?php
   $test=$_POST['test'];
   if ($test){
    foreach ($test as $t){echo 'You selected ',$t,'<br />';}
   }
?>
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    SharkZone Design Forum Index -> CGI, Perl, PHP, and SSI scripting All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group