Retrieve array from FORM List of values?

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

    #1

    Retrieve array from FORM List of values?

    Hi folks,

    Trying to fill in a gap in my understanding of php, and so this is rather
    newbish:

    I have created a form where a user selects 2 items from a list of 8 values.
    That form field is called "choices" and returns a value to the php file as
    $choices. This form posed no problem when I only allowed a single item to be
    selected, but the client now needs to have 2 items selected at a time.

    The problem I'm having is that I don't know how to turn the multiple
    selections on the form in to an array. I thought the $choices variable
    would automatically become an array, but
    Using[color=blue]
    > for ( $i = 0; $i<2; $i++ )
    > echo "$choices[$i] ";[/color]
    only returns the first two letters of the last selected item value.

    And
    [color=blue]
    > foreach($choice s as $articles)
    > echo $articles. ' ' ;[/color]

    Returns an invalid argument.

    While echo $choices returns the second item selected in the list, but not
    the first.
    It appears that the variable is replacing the first item selected with the
    second rather than returning an array.

    Any help appreciated.
    Thanks
    Jeff

    ~~~~~~~~~~~~
    Jefferis Peterson, Pres.
    Web Design and Marketing




    ----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
    http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
    ----= East and West-Coast Server Farms - Total Privacy via Encryption =----
  • Markku Uttula

    #2
    Re: Retrieve array from FORM List of values?

    Jefferis NoSpamme wrote:[color=blue]
    > That form field is called "choices" and returns a value to the php
    > file as $choices. This form posed no problem when I only allowed a
    > single item to be selected, but the client now needs to have 2 items
    > selected at a time.[/color]

    Read the fine manual... In your form, you need to set the name of the
    item as NAME="choices[]", and this way PHP receives it as $choices
    that is an array. Quite simple actually :)

    --
    Markku Uttula

    Comment

    • Jefferis NoSpamme

      #3
      Re: Retrieve array from FORM List of values?

      Thank You. I have 3 books I poured through, but none talked about using [ ]
      in an html form to transmit the multiple selections as an array. They only
      talked about iterating arrays from defined arrays.

      Thanks again,
      Jeff


      On 3/5/05 9:55 PM, in article OmuWd.3652$Cm2. 1431@reader1.ne ws.jippii.net,
      "Markku Uttula" <markku.uttula@ disconova.com> wrote:
      [color=blue]
      > Read the fine manual... In your form, you need to set the name of the
      > item as NAME="choices[]", and this way PHP receives it as $choices
      > that is an array. Quite simple actually :)
      >
      > --
      > Markku Uttula
      >[/color]

      ~~~~~~~~~~~~
      Jefferis Peterson, Pres.
      Web Design and Marketing




      ----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
      http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
      ----= East and West-Coast Server Farms - Total Privacy via Encryption =----

      Comment

      Working...