Working with Form Arrays in ColdFusion?

后端 未结 7 2061
旧时难觅i
旧时难觅i 2021-01-17 23:17

I have no idea how to handle this in ColdFusion 9, I have a form being submitted (POST) with element checkboxes, called items[].

When I do a

相关标签:
7条回答
  • 2021-01-17 23:52

    There's no Form Array’s in ColdFusion. Having '[]' at the end doesn't make it an array. You can access the checkbox values from form scope like this:

    FORM["ITEMS[]"]
    

    Dot notation doesn't work 'cause of the '[]'. See: http://help.adobe.com/en_US/ColdFusion/9.0/Developing/WSc3ff6d0ea77859461172e0811cbec22c24-7fb2.html

    Values from checkboxes are just comma separated values, which is a List in ColdFusion

    To loop through it, use cfloop list=:

    <cfoutput>
      <cfloop index="i" list="#FORM['ITEMS[]']#">    
        #i#
      </cfloop>
    </cfoutput>
    

    To convert a list to array, use ListToArray(). There are list functions like listGetAt(), but if you're doing lots of random access, it'd be smarter to convert the list into an array first.

    Thoughts, I'm kindof stumped and coldfusion isn't the easiest language to find examples / references on the net ;)

    • http://help.adobe.com/en_US/ColdFusion/9.0/Developing/index.html
    • http://learncf.com/tutorials
    • http://www.easycfm.com/
    • http://www.carehart.org/ugtv/
    0 讨论(0)
提交回复
热议问题