8 Replies Latest reply on Nov 18, 2009 6:36 AM by -==cfSearching==-

    Help with Looping Form.fieldnames to get count

    Fatlipcdn

      Hi all,

       

      I have searched the forum for the answer for this, and have found similar posts, but not quite what I am looking for.

       

      I have a form that submits values likes this: (All dynamically generated)

      APEN_INFRACTION_10
      APEN_INFRACTION_20
      APEN_INFRACTION_30
      APEN_INFRACTION_40
      APEN_INFRACTION_50
      APEN_INFRACTION_TYPE_10
      APEN_INFRACTION_TYPE_20
      APEN_INFRACTION_TYPE_30
      APEN_INFRACTION_TYPE_40
      APEN_INFRACTION_TYPE_50
      APEN_PER_11
      APEN_PER_21
      APEN_PER_32
      APEN_PER_40
      APEN_PER_50
      APEN_PLAYER_11
      APEN_PLAYER_21
      APEN_PLAYER_31
      APEN_PLAYER_41
      APEN_PLAYER_51

       

      The problem I am having is that when I am looping to set a value, the count moves beyond the form value that exists in the form.field. Obvioulsy it is looping all form fields, so the count of fields is greater than the form variable I am looking to cfset to something else.

       

      Example, if I loop this with the form values above:

      <cfset acount=0>
      <cfloop list="#form.fieldnames#" index="apen">
      <cfset acount=#acount#+1>   
      <cfif isDefined(FORM["APEN_PER_" & #acount#]) AND FORM["APEN_PER_" & #acount#] NEQ ''>
      Boo
      </cfif>

       

      The loop moves past  "APEN_PER_5" and goes to "APEN_PER_6" which throws an error because it doesn't exist.

       

      I would love to just loop the form field as a list, but for obvious reasons, I can't (or can I?).

       

       

      Any Ideas how to get the individual column count from the form field in this scenario?

       

      Thanks all,

      Greg