Filter system in ColdFusion 8

69 views Asked by At

I have been working on a small simple project on localhost for a client, it's a comment system with a filter.

But whenever I try to add the filter, it seems to get stuck on it's first word. I've been trying to search the answer on Google for almost 8 hours now, before posting here.

It's a simple query, no complex things. But anyone got any suggestions? I tried the # and cfloop, cfoutput, cfquery, etc. but nothing seems to work.

<cfquery name = "communityFilter" datasource = "#DSN#">
SELECT *
FROM cms_filter
</cfquery>


<!-- Query van de filter -->
<cfif form.comment CONTAINS communityFilter.word>
    Word gevonden!
<cfelseif NOT form.comment CONTAINS communityFilter.word>
    Geen word gevonden, system werkt =)
</cfif>

The system needs to take the word that is not allowed out of the database, but it keeps saying Word found while it's not found.

1

There are 1 answers

0
Dan Bracuk On

When you refer to a query result, you should specify the row number like this:

queryname.fieldname[rownumber]

If you don't you get the value from the first row. That's what is happening to you. While the comment might contain a bad word, you are not looking at all the available bad words. I suggest something like this.

commentHasBadWord = false;
for (badWord in ValueList(cms_filter.word)) {
if (commentHasBadWord == false && form.comment contains badWord)
commentHasBadWord = true;
else
break;
}

if commentHasBadWord == true;
//code for bad comment
else 
// code for good comment