Trouble getting UDF to work
I am trying to validate a form to find HTML after it is submitted (yes, I plan to code before submission as well, but I need to get this to work first). My UDF looks like this:
<cffunction name="checkChars" output="no" returntype="numeric">
<!--- define arguments --->
<cfargument name="Qfield" type="string" required="yes">
<!--- define variable(s) --->
<cfset Var dirtyParam = Arguments.Qfield>
<cfset Var QbadChar = 0>
<!--- check to see if HTML exists in Qfield --->
<cfif REFind("<",dirtyParam) NEQ 0><cfset QbadChar = 1></cfif>
<cfif REFind(">",dirtyParam) NEQ 0><cfset QbadChar = 1></cfif>
<cfif REFind("//",dirtyParam) NEQ 0><cfset QbadChar = 1></cfif>
<cfif REFind("c:",dirtyParam) NEQ 0><cfset QbadChar = 1></cfif>
<!--- If HTML exists, notify user and return to previous page --->
<cfif QbadChar NEQ 0>
<cfscript>
WriteOutput('
<script language="JavaScript">
<!--
alert("The data submitted in your form contains unallowable characters, please remove all non-alphanumeric characters.")
//-->
</script>
');
WriteOutput('
<script language="JavaScript">
<!--
history.back()
//-->
</script>
');
</cfscript>
</cfif>
<cfreturn QbadChar>
</cffunction>
It is saved in a separate template and included in the applicable template at the beginning with:
<cfinclude template="Libraries/formValidation.cfm">
I am testing it on a field called "Lessor" by calling the UDF in the same template with:
<cfif isdefined ("FORM.Lessor")><cfset #checkChars("Form.Lessor")#></cfif>
Unfortunately, it doesn't work because when I use HTML in the "Lessor" field, it goes ahead and saves it. Any ideas what I'm missing?
