How can I blow up an array that came from an html form in coldfusion?

I am completely new to ColdFusion (as of today actually). I don't know which version the server is using. I read some of to try and speed up.

My big question at the moment is, what is the ColdFusion equivalent for this PHP bit?

$numatt = $HTTP_POST_VARS['numatt'];
$attcount = count($att);


Here's the whole PHP script for context:

$nument = $HTTP_POST_VARS['nument']; # this is one number. My debug example is 2.
$numatt = $HTTP_POST_VARS['numatt']; # this is an indefinite number of numbers separated by commas. My debug example is 3,5.
$numval = $HTTP_POST_VARS['numval']; # this is one number. My debug example is 6.
echo 'number of entities is: $nument<br><br>';
$attcount = count($att);
echo 'the attributes are $numatt, which can be broken down to $att[1] and $att[2].<br><br>';
echo 'there are $numval values for each attribute.<br><br>';
for ($i = 1; $i = $nument; $i++) {
    echo 'this is round $i of the loop. It has $att[$i] attributes.<br><br>';
    for ($j = 1; $j = $att[$i]; $j++) {
        echo 'this is for attribute $j of entity $i.<br><br>';
        for ($k = 1; $k = $numval; $k++) {
            echo 'here is loop $k for $numval values.<br>';
        } #end $k
    } #end $j
} #end $i


Basically, I will need to translate this from PHP to ColdFusion, but I think I can figure out how to set up the loops if I spend enough time in the tutorials. (Or I'll come back with more questions ...) Pointers to better guides or links to get links would also be welcomed - I just found a google linked link.


source to share

1 answer

In ColdFusion, you can convert a string to an array using a function listToArray()

. All form variables are combined for you in scope form

. All url parameters are bound for you in scope url


<!--- reference variables submitted through a form --->
<p>name sent through form: #form.firstName#</p>

<!--- reference variable in url --->
<p>name in url: #url.firstName#</p>

<!--- converting strings into arrays, default delimiter is comma --->
<cfset arr1 = listToArray("my,list,is,cool", ",")>

<cfset arr2 = listToArray("my other list", " ")>

<cfset arr3 = listToArray("yet:another:list", ":")>

<!--- how many items in arr1? --->

<!--- loop over arr3 --->
<cfloop from="1" to="#arrayLen(arr3)#" index="i">


CFML makes most things easy. With that in mind, CFML also offers script syntax if you'd rather not use tags. Hope it helps



All Articles