Retrieve HTML array created from a list box

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • aktar
    New Member
    • Jul 2006
    • 105

    #1

    Retrieve HTML array created from a list box

    Hey folks, I was expecting an array to be returned with the following code for a multi-select dropdown list but I get single values. Can anyone help?


    Code:
    <?php
    
    	if(isset($_POST['submit'])){
    		
    		print_r($_POST);	
    		
    	}
    
    ?>
    
    
    <form method='post' >
    
        <select name="time" size=3 multiple>
            <option value="Morning">Morning</option>
            <option value="Day">Day</option>
            <option value="Night">Night</option>
        </select>
        
        <input type="submit" name='submit' value="submit" />
        
    </form>
    Last edited by Frinavale; Jan 18 '10, 06:36 PM. Reason: Moved from HTML to PHP.
  • Atli
    Recognized Expert Expert
    • Nov 2006
    • 5062

    #2
    Hey.

    If you want PHP to receive an array from a form, the <input> element(s) must end with [] brackets - in much the same manner you would use them with PHP variables.

    In your case:
    [code=html]<select name="time[]" size=3 multiple>[/code]

    Comment

    • aktar
      New Member
      • Jul 2006
      • 105

      #3
      Aha! thank you very much. Great help

      Comment

      Working...