SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    Free me php klassicd's Avatar
    Join Date
    Sep 2001
    Location
    San Diego
    Posts
    509
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Grabbing Selext Box Multiple Values

    PHP Code:
    <form name="form1" method="post" action="">
      <select name="select" size="4" multiple>
        <option value="Test 1">Test 1</option>
        <option value="Test 2">Test 2</option>
        <option value="Test 3">Test 3</option>
        <option value="Test 4">Test 4</option>
      </select>
      <br>
      <input type="submit" name="Submit" value="Submit">
    </form>
    <?php 
     
    if($_POST) {
      echo 
    $_POST['select'];
     }
    ?>
    If I select more than one item in the select box, for example Test 1 and Test 3, echo $_POST['select'];will pnly print the last value selected. Using PHP how do I list all the values selected? Is it possible?

  2. #2
    SitePoint Addict rabbitdog's Avatar
    Join Date
    Jul 2001
    Location
    So. Tenn.
    Posts
    363
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    <select name="select[]" size="4" multiple
    $_POST['select'] will be available as array which you can loop through to get the individual values. This works for checkboxes as well.
    Mr Vector
    High quality, royalty free, vector graphics
    for t-shirt artists and graphic/web designers.

  3. #3
    Free me php klassicd's Avatar
    Join Date
    Sep 2001
    Location
    San Diego
    Posts
    509
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks. Easy fix.

  4. #4
    SitePoint Enthusiast Igloo's Avatar
    Join Date
    Dec 2002
    Location
    Australia
    Posts
    61
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Does the form select name attribute have to be "blah[]", as in do you have to have the common PHP array language "[]" ?

    As I use loops in my scripts, I will have forum elements named "options[status]" or "settings[message]" etc, would that conflict with the array kept inside a multiple selectable select menu?

    Thankyou,

    Igloo...


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •