Multiple Get's ...

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • SuperStar
    New Member
    • Feb 2007
    • 3

    Multiple Get's ...

    Okey .. so , i have a problem ... in one of my forms i have this element:
    [HTML]
    <select name="list" multiple="multi ple" size="10" >
    <option value="Opt1">Op t1</option>
    <option value="Opt2">Op t2</option>
    <option value="Opt3">Op t3</option>
    <option value="Opt4">Op t4</option>
    </select>
    [/HTML]
    The user can and will select multiple items.
    I see that when the form is submited the selected variabiles are passed like this:

    page.php?list=O pt1&list=Opt2


    How can i get through GET or POST all the selected options in the form after the user submits the form ?
  • Motoma
    Recognized Expert Specialist
    • Jan 2007
    • 3236

    #2
    Originally posted by SuperStar
    Okey .. so , i have a problem ... in one of my forms i have this element:
    [HTML]
    <select name="list" multiple="multi ple" size="10" >
    <option value="Opt1">Op t1</option>
    <option value="Opt2">Op t2</option>
    <option value="Opt3">Op t3</option>
    <option value="Opt4">Op t4</option>
    </select>
    [/HTML]
    The user can and will select multiple items.
    I see that when the form is submited the selected variabiles are passed like this:

    page.php?list=O pt1&list=Opt2


    How can i get through GET or POST all the selected options in the form after the user submits the form ?
    Welcome to The Scripts.
    The tata elements will be in an array named $_POST['list'].
    Run a print_r() on it to see what it looks like.

    Comment

    • SuperStar
      New Member
      • Feb 2007
      • 3

      #3
      Doesn`t work ..

      i use GET in the form instead of POST for the moment to see if the values are passed .. and they are

      page.php?list=O pt1&list=Opt2&. ...

      But the print_r only get's first variabile ..

      Comment

      • Motoma
        Recognized Expert Specialist
        • Jan 2007
        • 3236

        #4
        Originally posted by SuperStar
        Doesn`t work ..

        i use GET in the form instead of POST for the moment to see if the values are passed .. and they are

        page.php?list=O pt1&list=Opt2&. ...

        But the print_r only get's first variabile ..
        Try using POST instead.

        Comment

        • SuperStar
          New Member
          • Feb 2007
          • 3

          #5
          Okey .. POST and GET are the same with the difference that POST doesn't give the chance of simple users to "play" with pages ( aka more secure for the site ).


          I don`t think many of you know .. i've been searching a lot more and I found the answer .. So when you use a select with multiple options you have to cheat to let php recognize it.

          When processing the request, php puts all selected options in the select object's name, but treats it like an array. If it is not an array, only the last option is remembered.

          So to cheat you should append [ ] to the name of the select

          <form .. ... ..>
          <select multiple="multi ple" name="myselect[]" size="3">
          <option value="1">1st option</option>
          <option value="2">2nd option</option>
          <option value="3">3rd option</option>

          ...

          Then in the processing part:
          <?php
          if(!empty[$_REQUEST['myselect']) print_r($_REQUE ST['myselect']);
          ?>

          Comment

          • Motoma
            Recognized Expert Specialist
            • Jan 2007
            • 3236

            #6
            Glad you were able to find your own answer.
            Thanks for posting it back to us.

            Comment

            Working...