Skip to main content
Participating Frequently
May 10, 2010
Question

exclude one field from application.cfm loop

  • May 10, 2010
  • 1 reply
  • 522 views

i am using a cfloop collection tag in the application cfm file to loop through and remove special charachters from submitted forms for xss protection. I want to exclude one or two fields from this because they are date time fields so can't have all the restrictions all of the other fields can. I am picturing something like

<cfloop collection="blah" item="blahblah">

     <cfif field name is not one of the date time fields>

< general remove bad charachters code>

     <cfelseif field name is one of date time fields>

<remove special charachters code>

</cfif>

</cfloop

how do i get the field name to use in the condition above?

    This topic has been closed for replies.

    1 reply

    ilssac
    Inspiring
    May 10, 2010

    godfogged wrote:

    how do i get the field name to use in the condition above?

    How do you want to get it?  This is not something ColdFusion is going to know, it is something you, as the developer, are going to have to tell it.  Either by hard coding the field names to exclude into the <cfif...> or providing them from some other data source.  It is up to you to figure out.

    godfoggedAuthor
    Participating Frequently
    May 10, 2010

    what is the syntax for hard coding them?

    ilssac
    Inspiring
    May 10, 2010

    Ummm...

    <cfloop collection="form" item="field">

    <cfif field NEQ "aDateField" AND field NEQ "bDateField" AND field NEQ "cDateField">

       Processs the non-date fields

    <cfelse>

      Process the date fields

    </cfif>

    </cfloop>

    Or slightly easier to maintain.

    <cfloop collection="form" item="field">

    <cfif NOT ListFind(field, "aDateField,bDateField,cDateField")>

       Processs the non-date fields

    <cfelse>

      Process the date fields

    </cfif>

    </cfloop>

    Or the best yet, would be to provide the list you are checking against from sometype of data repository where it is easy to maintain, like a database or configuration or something.  But I will leave that exercise to you to figure out.