Discussion:
referencing html form array
(too old to reply)
Bacteria Man
2005-02-28 19:12:17 UTC
Permalink
I'm trying to collect the values from an html form array. For example: <input
type='text' name='order[3]' value='4'> <input type='text' name='order[7]'
value='5'> <input type='text' name='order[9]' value='8'> I then attempt to
convert the array to a list: <cfif isdefined('form.order')> <cfset arrOrder
= arraytolist(form.order, ',')> <cfoutput>#myList#</cfoutput> </cfif>
ColdFusion doens't recognize the form array. Thanks in advance.
blewis
2005-02-28 19:30:10 UTC
Permalink
As far as I know, this is not a valid naming convention. CF will not create
an array out of the form variables just because you put square brackets in the
name. You will end up not with an array, but with three form variables called
form.order[3], form.order[7], and form.order[9]. If you want a list of values,
just name all of the form inputs the same thing and use the POST method. When
using POST, any form input items named the same thing will result in a single
form variable with the values in a comma-separated list. So if you named all
three text inputs "order", then you would get a variable called #form.order#
with a value of "4,5,8".

Bryan
Bacteria Man
2005-02-28 19:50:31 UTC
Permalink
Bryan, thanks for your reply. I'm aware that giving input fields the same name
will create a comma delimited list. I was hoping for something like in my
example, which is valid PHP syntax and makes things pretty easy. I need the
order ID AND value so in ColdFusion I could do something like <input
type='text' name='order3' value='4'> <input type='text' name='order7'
value='5'> <input type='text' name='order9' value='8'> ...and then loop
through the elements... unless you can think of something more efficient.
Thanks.

Continue reading on narkive:
Loading...