[thelist] Trim all FORM.fieldnames in ColdFusion?

Aaron Johnson ajohnson at mindseye.com
Wed Apr 25 15:38:52 CDT 2001


Here's a custom tag to do what you want:

<cfsetting enablecfoutputonly="1">
<!---
	custom tag <cf_trimformfields>

	trims the values of all form fields posted to the page.
	This tag ensures compatibility with Mac browsers that
	add whitespace and CR/LF characters to form field values.

	WARNING: If Trim() is applied to any field of type "IMAGE", that
		field will fail.

	USAGE: <cf_trimformfields>
--->

<cfparam name="attributes.excludeFields"
default="img,image,thumb,photo,video">
<cfparam name="attributes.excludeExact" default="0">

<!--- build our "if" statement - this prevents excessive looping --->
<cfset ifstring = "">
<cfset lastExclude = ListLast(attributes.excludefields)>
<cfloop list="#attributes.excludeFields#" index="fld">
	<cfset ifstring = ifstring & "FindNoCase(""#fld#"", thisfield)">
	<cfif fld neq lastExclude>
		<cfset ifstring = ifstring & " OR ">
	</cfif>
</cfloop>

<!--- loop through fields and Trim() for Mac --->
<cfif IsDefined("form.fieldnames")>
	<cfloop list="#form.fieldnames#" index="thisfield">
		<cfif NOT Evaluate(ifstring)>
			<cfset form[thisfield] = Trim(form[thisfield])>
		</cfif>
	</cfloop>
</cfif>


<cfsetting enablecfoutputonly="0">


HTH's.

Aaron Johnson, MCSE, MCP+I
Allaire Certified ColdFusion Developer
MINDSEYE, Inc.
<phn>617.350.0339
<fax>617.350.8884
<icq>66172567
ajohnson at mindseye.com

> -----Original Message-----
> From: thelist-admin at lists.evolt.org
> [mailto:thelist-admin at lists.evolt.org]On Behalf Of faust at ThinkChurch.com
> Sent: Wednesday, April 25, 2001 6:43 PM
> To: thelist at lists.evolt.org
> Subject: [thelist] Trim all FORM.fieldnames in ColdFusion?
>
>
> Is there a way to just Trim all of the #FORM.fieldnames# in
> ColdFusion.  Something like:
>
> <CFIF #ParameterExists(FORM.fieldnames)#>
>  <CFSET #fieldnames_processed# = "">
>  <CFLOOP INDEX="form_element" LIST="#FORM.fieldnames#">
> 	<CFIF #ListFind(#fieldnames_processed#, #form_element#)# IS 0>
> 	   <CFSET #form_element_qualified# = "FORM." & #form_element#>
> 	   <CFSET #form_element_qualified# = Trim(#form_element_qualified#)>
> 	   <CFSET #fieldnames_processed# =
> #ListAppend(#fieldnames_processed#, #form_element#)#>
>    </CFIF>
>  </CFLOOP>
> </CFIF>
>
> but that works.  :-)
>
>
> TIA
>
> Faust
>
>
> "Miss Morris, I'm perfectly capable of fixing my own
>  breakfast.  As a matter of fact, I had a peanut butter
>  sandwich and two whiskey sours."
> -- Richard Sherman, _The Seven-Year Itch_
>
> ---------------------------------------
> For unsubscribe and other options, including
> the Tip Harvester and archive of TheList go to:
> http://lists.evolt.org Workers of the Web, evolt !





More information about the thelist mailing list