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 http://help.adobe.com/livedocs/coldfusion/8/htmldocs/help.html?content=Part_4_CF_DevGuide_1.html 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'];
$att=explode(",",$numatt);
$attcount = count($att);

      

Here's the whole PHP script for context:

<?php
$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>';
$att=explode(",",$numatt);
$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.

+3


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? --->
#arrayLen(arr1)#

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

      



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

+6


source







All Articles