I am almost there. With a little insight into the code you provided me
, I came up with this:
<CFQUERY NAME="q_profanity" DATASOURCE="9130.ww">
SELECT term
FROM profanity;
</CFQUERY>
<HTML>
<HEAD>
<TITLE>New Guestbook Entry</TITLE>
</HEAD>
<BODY>
<TABLE
WIDTH="100%"
HEIGHT="100%"
BORDER="0">
<TR>
<TD ALIGN="center" VALIGN="middle">
<cfset bValidationPassed = true>
<cfloop query="q_profanity">
<cfif FindNoCase(term, form.gb_entry_m)>
You have included a term or phrase which is unacceptable to our records in your guestbook message. <cfset bValidationPassed = false>
<cfbreak>
</cfif>
</cfloop>
Your guestbook message has been saved.
<BR>
<A HREF="gb_entry_rvw.cfm?call_number=#gb_entryID#">Review Your Entry Now!</A>
</TD>
</TR>
</TABLE>
</BODY>
</HTML>
It's just swapping out the message centered on teh page, but I get "Your message has been saved." in addition to the "You have included..." message.
I know I'm close - I just need to have only one statment or the other display.
Doug
Close, but I can spot a couple things wrong with the logic there right off the bat:
1) Your code is missing the INSERT statement in order to add the data to your database (on success) - without it your user's post will never make it into your system
2) You need to make the message that appears after the validation runs conditional on the results of the validation. As you've coded it now, your "success" message is hard coded so that it appears regardless of whether the validation has passed or not.
Try the following blueprint:
<!--- Set Default Values --->
<cfset bValidationPassed = true>
<cfset sMessage= "">
<!--- Retrieve Words --->
<CFQUERY NAME="q_profanity" DATASOURCE="9130.ww">
SELECT term
FROM profanity;
</CFQUERY>
<!--- Detect the use of stored words --->
<cfloop query="q_profanity">
<cfif FindNoCase(term, form.gb_entry_m)>
<cfset bValidationPassed = false>
<cfbreak>
</cfif>
</cfloop>
<!--- Conditional logic depending on whether profanity term was detected --->
<cfif bValidationPassed eq true>
<!--- No profanity: add post --->
<CFQUERY NAME="q_AddRecord" DATASOURCE="9130.ww">
[INSERT SQL HERE]
</CFQUERY>
<!--- Set message text --->
<cfsavecontent variable="sMessage ">
<p>Your guestbook message has been saved.</p>
<!--- you will need to determine the new entry ID in the Add Record SQL above --->
<p><A HREF="gb_entry_rvw.cfm?call_number=#gb_entryID#">Review Your Entry Now!</A></p>
</cfsavecontent>
<cfelse>
<!--- If profanity detected, show error text --->
<cfset sMessage = "You have included a term or phrase which is unacceptable to our records in your guestbook message. ">
</cfif>
<!--- Generate output HTML --->
<HTML>
<HEAD>
<TITLE>New Guestbook Entry</TITLE>
</HEAD>
<BODY>
<!--- display message --->
<cfoutput>#sMessage#</cfoutput>
</BODY>
</HTML>