Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    May 2005
    Posts
    563
    Thanks
    0
    Thanked 3 Times in 3 Posts

    multiple select box

    What does a select box (multiple selections allowed) post when a form is submitted?

    is it an array? Would something like this code work?

    PHP Code:
    <?php
    for ($i 0;$i count($_POST['select']);$i++) {
        echo 
    $_POST['select'][$i];
    }
    ?>

  • #2
    Regular Coder
    Join Date
    Feb 2005
    Location
    West Midlands, UK
    Posts
    623
    Thanks
    0
    Thanked 0 Times in 0 Posts
    It will create an array but only if you use [] brackets in the field name, otherwise you just get the last selected value.
    PHP Code:
    <form action="<?php echo basename($_SERVER['PHP_SELF']); ?>" method="post" enctype="multipart/form-data" name="form1">
      <select name="select[]" size="3" size="1" multiple>
        <option value="value1">Option1</option>
        <option value="value2">Option2</option>
        <option value="value3">Option3</option>
      </select>
      <input type="submit" name="submit" value="submit" />
    </form>

    <?php
    if($_POST) {
        for (
    $i 0;$i count($_POST['select']);$i++) { 
            echo 
    $_POST['select'][$i] . '<br />'
        }
    }
    ?>

  • #3
    Regular Coder
    Join Date
    May 2005
    Posts
    563
    Thanks
    0
    Thanked 3 Times in 3 Posts
    k thanks


  •  

    Posting Permissions

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