Connecting Tech Pros Worldwide Forums | Help | Site Map

Retrieve array from FORM List of values?

Jefferis NoSpamme
Guest
 
Posts: n/a
#1: Jul 17 '05
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($choices 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
http://www.PetersonSales.com



----== 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
Guest
 
Posts: n/a
#2: Jul 17 '05

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

Jefferis NoSpamme
Guest
 
Posts: n/a
#3: Jul 17 '05

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.news.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
http://www.PetersonSales.com



----== 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 =----
Closed Thread