SebTags 1.0 Documentation: Filters


The "filter" attribute of cf_sebForm takes a component (or array of components). If that attribute exists, cf_sebForm will pass the Form structure into the "filter" method of the component(s) passed in to that attribute and set the Form structure to the result.

Some uses for this could include spam, security, or offensive language.

If the filter method throws an error, then it will be treated just like an error caught by the CatchErrTypes attribute for validation errors.

Using Filter

SpamFilter.cfc is an example filter. Assuming it is instantiated into Application.SpamFilter, you could use it like this:

<cf_sebForm filter="#Application.SpamFilter#">

Create a Filter Component

It should be relatively easy to create a filter. Since my wife went to UNC and they have a big rivalry with Duke, I am going to make a quick TarHeel.cfc. The filter method will change any reference of "devil" into "demon" and reject anything that includes "Duke".


<cffunction name="filter" access="public" returntype="struct" output="no">
	<cfargument name="mydata" type="struct" required="yes">
	<cfset var key = "">
	<cfloop collection="#arguments.mydata#" item="key">
		<cfif StructKeyExists(arguments.mydata,key)>
			<cfif arguments.mydata[key] CONTAINTS "Duke">
				<cfthrow message="No Duke allowed!">
			<cfif arguments.mydata[key] CONTAINTS "Devil">
				<cfset arguments.mydata[key] = ReplaceNoCase(arguments.mydata[key],"Devil","Demon","All")>
	<cfreturn arguments.mydata>


The component must have a function named "filter" which must be public and return a struct. The first argument must take a struct (though the argument can have any name). Errors returned by the filter can be of any type at all.