Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 3 of 3
  1. #1
    Junior Member
    Join Date
    Sep 2005
    Posts
    7
    Member #
    11300
    How do I create arrays in a HTML <form>?

  2.  

  3. #2
    Senior Member Fallout's Avatar
    Join Date
    Aug 2003
    Location
    Richmond, Virginia
    Posts
    543
    Member #
    2748
    You can simply give the elements, say a bunch of checkboxes, the name of your array followed by empty braces.

    Code:
    <form ... method='post'>
    <input ... id='array_name[]' />
    <input ... id='array_name[]' />
    <input ... id='array_name[]' />
    </form>
    
    <!-- note that the "..." simply replace any other styles or other attributes -->
    Then in your PHP you can get the values by using $_POST['array_name'][0] for the first value, and $_POST['array_name'][1] etc. for the rest.

  4. #3
    Senior Member
    Join Date
    Jun 2005
    Location
    Atlanta, GA
    Posts
    4,146
    Member #
    10263
    Liked
    1 times
    You can also put actual information between the []s, I believe, so you can do <input ... id="array_name['test']" /> to get $_POST['array_name']['test']. I might be wrong about that, though.

    This comes in particularly useful with multiple-select boxes:
    HTML Code:
    <select multiple="true" name="select[]">
        <option>...</option>
        ...
    </select>
    This will get you an array, select, which will contain all of the selected options.


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 08:44 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com