getting multiple data from <select>

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Sonnich

    #1

    getting multiple data from <select>

    Can anyone give me a quick hint for this?

    Say, I have: <SELECT NAME="opt3" SIZE="15" multiple>

    Then I'd like to list the items selected...
    echo $_POST["opt3"];
    but this gives only the first one

    how do I get the rest?

  • P Pulkkinen

    #2
    Re: getting multiple data from &lt;select&g t;

    "Sonnich" <sonnich.jensen @elektrobit.com kirjoitti
    viestissä:11707 72126.596200.67 550@s48g2000cws .googlegroups.c om...
    Can anyone give me a quick hint for this?
    Say, I have: <SELECT NAME="opt3" SIZE="15" multiple>
    Then I'd like to list the items selected...
    echo $_POST["opt3"];
    but this gives only the first one
    how do I get the rest?

    <SELECT NAME="opt3()" SIZE="15" multiple>

    Parenthesis is the point: NAME="opt3()"

    Then php knows than an array is coming. This is not because html would
    require that, but because php does. This applies not only to select
    elements, but checkboxes as well for example. Or sometimes you may want to
    send some array in hidden fields.



    Comment

    • Sonnich

      #3
      Re: getting multiple data from &lt;select&g t;

      On Feb 6, 4:36 pm, "P Pulkkinen"
      <perttu.POISTAT AMA.pulkki...@P OISTATAMA.elisa net.fiwrote:
      "Sonnich" <sonnich.jen... @elektrobit.com kirjoitti
      viestissä:11707 72126.596200.67 ...@s48g2000cws .googlegroups.c om...
      >
      Can anyone give me a quick hint for this?
      Say, I have: <SELECT NAME="opt3" SIZE="15" multiple>
      Then I'd like to list the items selected...
      echo $_POST["opt3"];
      but this gives only the first one
      how do I get the rest?
      >
      <SELECT NAME="opt3()" SIZE="15" multiple>
      >
      Parenthesis is the point: NAME="opt3()"
      >
      Then php knows than an array is coming. This is not because html would
      require that, but because php does. This applies not only to select
      elements, but checkboxes as well for example. Or sometimes you may want to
      send some array in hidden fields.
      eeehhh I tried to play a bit around with this, but do I also need a
      trick to read it out?

      BR
      Sonnich

      Comment

      • P Pulkkinen

        #4
        Re: getting multiple data from &lt;select&g t;


        "Sonnich" <sonnich.jensen @elektrobit.com wrote

        "eeehhh I tried to play a bit around with this, but do I also need a
        trick to read it out?"

        Well, you need to loop through the array:

        foreach ($opt3 as $key =$val)
        {
        echo "<p>".htmlspeci alchars($key)." =".htmlspecialc hars($val)."</p>n";
        }

        That's something for ONE-dimensional array, though. Remember, no parenthesis anymore.

        Comment

        • Rik

          #5
          Re: getting multiple data from &lt;select&g t;

          Sonnich <sonnich.jensen @elektrobit.com wrote:
          On Feb 6, 4:36 pm, "P Pulkkinen"
          <perttu.POISTAT AMA.pulkki...@P OISTATAMA.elisa net.fiwrote:
          >"Sonnich" <sonnich.jen... @elektrobit.com kirjoitti
          >viestissä:1170 772126.596200.6 7...@s48g2000cw s.googlegroups. com...
          >>
          Can anyone give me a quick hint for this?
          Say, I have: <SELECT NAME="opt3" SIZE="15" multiple>
          Then I'd like to list the items selected...
          echo $_POST["opt3"];
          but this gives only the first one
          how do I get the rest?
          >>
          ><SELECT NAME="opt3()" SIZE="15" multiple>
          >>
          >Parenthesis is the point: NAME="opt3()"
          >>
          >Then php knows than an array is coming. This is not because html would
          >require that, but because php does. This applies not only to select
          >elements, but checkboxes as well for example. Or sometimes you may want
          >to
          >send some array in hidden fields.
          >
          eeehhh I tried to play a bit around with this, but do I also need a
          trick to read it out?

          Well, don't use () in the name, but []...

          A little hint for debugging POSTs: echo file_get_conten ts('php://input')
          will give you the raw input.

          Example:
          ------------------
          POST:
          <?php
          var_dump($_POST );
          ?>
          INPUT:
          <?php
          echo file_get_conten ts('php://input');
          ?>
          <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
          <select name="check()" multiple>
          <option>optio n 1</option>
          <option>optio n 2</option>
          <option>optio n 3</option>
          <option>optio n 4</option>
          <option>optio n 5</option>
          <option>optio n 6</option>
          </select>
          <select name="check2[]" multiple>
          <option>optio n q</option>
          <option>optio n e</option>
          <option>optio n r</option>
          <option>optio n t</option>
          <option>optio n y</option>
          <option>optio n u</option>
          </select>
          <input type="submit">
          </form>
          ------------------
          --
          Rik Wasmus

          Comment

          • P Pulkkinen

            #6
            Re: getting multiple data from &lt;select&g t;


            "Rik" <luiheidsgoeroe @hotmail.comwro te
            Well, don't use () in the name, but []...
            Oops, thanks for correction.


            Comment

            Working...