Copy link to clipboard
Copied
Is there anyway to exclude some form fields while looping over others? If I could just not loop over certain form fields on the action page it would be perfect. Not sure if this is possible. I am passing items from the form and appending or deleting them to a list....but I don't want all of the form fields to do this.
Right now the code is:
<cfloop list="#form.fieldnames#" index="i" delimiters=",">
Doing functions in here to append, delete items from the form into a list.
</cfloop>
You could just add a conditional statement to your loop. Something like this might work.
<cfif listContains(i,"list,of.fields,to,include")>
OR
<cfif NOT listContains(i,"list,of,fileds,to,exclude")>
Copy link to clipboard
Copied
You could just add a conditional statement to your loop. Something like this might work.
<cfif listContains(i,"list,of.fields,to,include")>
OR
<cfif NOT listContains(i,"list,of,fileds,to,exclude")>
Copy link to clipboard
Copied
Well the form fields are always going to be present and I need to pass them for a different part of the page. I guess
what I am looking for is the CFLOOP to only loop over certain form fields, not all of them. I don't know if that is possible.
Copy link to clipboard
Copied
Create a list of fields you want to include and loop through that.
Copy link to clipboard
Copied
<cfif listContains(i,"list,of.fields,to,include")>
I am sure that is just concept. Ian knows the difference.
But if you do use listContains, make sure you understand how it operates. It searches for substrings, not whole values. So searching for "the" would also match the list elements "theme" and "theatre". That often surprises people. If you need an exact match, you are often better off using listFind/listFindNoCase.
-Leigh
Copy link to clipboard
Copied
Ah yes, listFInd() is the function one probably wants to use in this situation.
But yes, just a concept as shown by the mixed delimiters in my example list.
Copy link to clipboard
Copied
Thanks for the help. Much appreciated as always!