Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Exclude form fields from cfloop

Participant ,
Sep 09, 2010 Sep 09, 2010

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>

1.2K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Valorous Hero , Sep 09, 2010 Sep 09, 2010

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")>

Translate
Valorous Hero ,
Sep 09, 2010 Sep 09, 2010

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")>

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Sep 09, 2010 Sep 09, 2010

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.


Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 09, 2010 Sep 09, 2010

Create a list of fields you want to include and loop through that.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Sep 09, 2010 Sep 09, 2010

<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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Sep 09, 2010 Sep 09, 2010

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Sep 10, 2010 Sep 10, 2010
LATEST

Thanks for the help. Much appreciated as always!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources