Help with Looping Form.fieldnames to get count
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_1 | 0 |
| APEN_INFRACTION_2 | 0 |
| APEN_INFRACTION_3 | 0 |
| APEN_INFRACTION_4 | 0 |
| APEN_INFRACTION_5 | 0 |
| APEN_INFRACTION_TYPE_1 | 0 |
| APEN_INFRACTION_TYPE_2 | 0 |
| APEN_INFRACTION_TYPE_3 | 0 |
| APEN_INFRACTION_TYPE_4 | 0 |
| APEN_INFRACTION_TYPE_5 | 0 |
| APEN_PER_1 | 1 |
| APEN_PER_2 | 1 |
| APEN_PER_3 | 2 |
| APEN_PER_4 | 0 |
| APEN_PER_5 | 0 |
| APEN_PLAYER_1 | 1 |
| APEN_PLAYER_2 | 1 |
| APEN_PLAYER_3 | 1 |
| APEN_PLAYER_4 | 1 |
| APEN_PLAYER_5 | 1 |
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
