Problems with array in form object

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Blackmore
    New Member
    • Mar 2007
    • 25

    Problems with array in form object

    For multiple records of a similar type in a database query, I am attempting to define some checkbox form elements from the query using an array:

    [CODE=cfm]
    <cfset temp=ArrayNew(1 )>
    <cfset i=1>
    <cfloop query="myQuery" >
    <cfset temp[#i#]=#myQuery.colNa me#>
    <cfinput type="checkbox" name="temp[#i#]" value="#temp[i]#"/>
    <cfset i=i+1>
    </cfloop>
    [/CODE]

    This seems to work fine in setting up the checkboxes and for returning the correct values when the form is submitted, as the <cfdump> function does display the values as required. However, the variables do not appear as if they are part an array in the <cfdump> display. Instead they appear as normal structure variables such as the 'submit' variable in the form object:

    temp[1] {correct value}
    temp[2] {correct value}
    temp[3] {correct value}
    submit 'submit'
    etc.

    Additionally, when I attempt to reference the variables for further manipulaton, using for example the 'IsDefined' function, the variables cannot be accessed. For example the following does not work:

    [CODE=cfm]<cfif IsDefined("form .temp[1]")>[/CODE]

    Am I doing this correctly? Can anyone suggest where I am going wrong and what I should be doing instead?

    Regards

    Blackmore
    Last edited by acoder; Sep 12 '07, 11:43 AM. Reason: fixed code tags
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    isDefined doesn't check the existence of array elements.

    Try using cfparam instead.

    Comment

    Working...