CFLoop through form fields problem
Hi all,
Maybe someone may know this answer but it's driving me nuts.
I am looping through form fields from another page and trying to gather form field name values from dynamic checkboxes.
I want to extract the ID values built into the names...and delete those records.
Each checkbox name begins with "img_". (For example : img_59)
This is the code I am using :
----------------------------------------------------------------------------------------------------
<cfloop index="i" list="#Form.FieldNames#" delimiters=";">
<cfif LEFT(i, 4) IS "img_">
<CFSET selectImageID = RemoveChars(i, 1, 4)>
<CFSET selectImageID = #Evaluate(selectImageID)#>
</cfif>
<!--- Delete Query for selected image IDs --->
<cfquery name="deleteImages" datasource="ctmprojects">
DELETE
FROM photos
WHERE ID = #selectImageID#
</CFQUERY>
</cfloop>
<cflocation url="edit.cfm?ID=#Form.ID#">
----------------------------------------------------------------------------------------------------
The form has one hidden field with an "ID" value.... but most are dynamic checkboxes that have names that start with "img_".
I need to loop through these to capture the Record numbers of the images to delete.
The problem is : it does not seem to be looping a single name value at a time....
If I do a <cfoutput>#i#<br></cfoutput> at the beginning or end of the loop I get a full list of form values each time ... such as...
ID,IMG_61,IMG_63
This is causing it to not evaluate the first 4 characters of each.
The code works if the form only has one checkbox because the result is one value... but with multiple form fields it's always one long string with the delimiters... ![]()
Does anyone have a clue as to what is going on?.... Or is there a better method of doing this?
Thanks so much
Tim Roman
