Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

valuelist issue 2

Status
Not open for further replies.

GUJUm0deL

Programmer
Jan 16, 2001
3,676
US
I am using valuelist to put all values in a query into a list, but for some reason I the list returns:

one ,two ,three ,four ,five ,etc...

Why is there a space then a comma? The space shouldn't be there...


____________________________________
Just Imagine.
 
change your index to something other than FAList lets see some sample input from a user.

Human beings, who are almost unique in having the ability to learn from the experience of others, are also remarkable for their apparent disinclination to do so.
-Douglas Adams (1952-2001)
 
I'm going home i'll see you in a half hour i expect this to be done by the time i get there. :)

have a good weekend.

Human beings, who are almost unique in having the ability to learn from the experience of others, are also remarkable for their apparent disinclination to do so.
-Douglas Adams (1952-2001)
 
Ok, I changed the list to another var, ran the code and it did the same thing. It scrubbed everything.

Code:
<cfset badwordslist = valuelist(badwordscheck.BD)>
<cfset badWordsstatus = 0>

<cfoutput>
  <cfloop index="somethingelse" from="1340" to="1343">
    <cfset FAList = listappend(FAList,trim(FormAnswer))>
      <cfset FAList = Replace(FAList," ",",","ALL")>
    <cfloop list="#FAList#" index="i" delimiters="|,">
      <cfif findnocase(i,#badwordslist#)>
        <cfset badWordsstatus = badWordsstatus + 1>
      </cfif>            
    </cfloop>
      <cfset FAList = "">
  </cfloop>    
</cfoutput>
<cfif badWordsstatus EQ 0>
...
...
</cfif>


____________________________________
Just Imagine.
 
ok, it does what I would expect
here is my example


if i put in "joe|,poop|,alex|,house"
i get nothing <! expected !>

if i put in "joe,poop,alex,house"
i get nothing <! expected !>

if i put "joe|,alex|,house"
i get ... ... <! expected !>

give us user input so we can see what's up.

Human beings, who are almost unique in having the ability to learn from the experience of others, are also remarkable for their apparent disinclination to do so.
-Douglas Adams (1952-2001)
 
GujumOdel: what is the numeric value for? (1340-1343) is this going to be dynamic? what do you need it for?

Plus why would you like that numeric value added to the input coming from the user?

I'm assuming you only have a long comment entry from the user and you just want to get rid of the curse words before posting back to the Internet, correct?



grtfercho çB^]\..
"Imagination is more important than Knowledge" A. Einstein
-----------------------------------------------
 
Hey guys. Sorry for the delay in responding.

bombboy, I changed my INDEX to another name, and re-ran the file, and the same thing happened. All information gets scrubbed. What happens is a user will fill out the form and submit, then I take all the answers and send them to someone else. but before that I loop through the field values to see if any bad words are found, if any are found, I scrub that entire entry (as in that users replies do not get sent).

grtfercho, the 1340-1343 represents a fieldID that I generate, these numbers come from another table. This is the only I can refer to a specific form and its fields. Now, any forms where I use the bad words script will have these numbers changed. Makes sense??

I changed the INDEX name to something, and the same thing happens, any ideas??

Thans.


____________________________________
Just Imagine.
 
I still don't understand why you need the Numeric index added to the list of values coming from the user.

Anyhow, I played with the code a bit and I ended up with the following.
Code:
<body>
<cfset badwordslist = "uno,dos,tres,cuatro,cinco,seis,siete">
<cfset badWordsstatus = 0>

<cfoutput>
  <cfloop index="FAList" from="1340" to="1343">
  <cfoutput><hr>Beginning: #FALIST#<br></cfoutput>
  <!---At this point FAList is just a number, nothing else--->
    <cfset FAList = listAppend(FAList,[b]'uno cinco,           diez'[/b])>
	<!--get whatever the user provided and added to FAList: Results in a number, a comma and the entry from the user--->
	
	<cfset FAList = replaceNocase(Falist," ",",","ALL")> 
<!--- replace all spaces with a comma. Good but if you have multiple spaces you end up with ",,,,,,,, "empty elements that will get processed.--->
<cfoutput>Middle: #FALIST#<br></cfoutput> 
	<cfset FAList = reReplaceNoCase(Falist,",{2,}",",","ALL")>
<!---since something like "uno ,  dos" will get transformed into "uno,,,dos" then we need to replace every place where there are more than two commas with only one. We use Regexp for that.--->
<!---Now we have a nice clean list separated by commas and with no empty elements--->
<!---We need to loop through the list and compare  each element to the BadWordsList, if we find one then increase the counter--->
   <cfloop list="#FAList#"  index="usrToken">
      <cfif listFindNoCase(badWordsList,usrToken) eq 0>
        <cfset badWordsstatus = badWordsstatus + 1>
      </cfif>            
    </cfloop> 
      <cfset FAList = "">
  </cfloop>    
</cfoutput>
</body>




Hope that helps or at least gives you more ideas.

grtfercho çB^]\..
"Imagination is more important than Knowledge" A. Einstein
-----------------------------------------------
 
grtfercho, thanks for the reply. The numeric index isn't coming from the user, it's coming from the database. I am letting the user submit the values, then I query the dB. Its kind of hard to explain the set-up, but the gist of this is:
1) user submits form
2) i query the dB to retrieve answers
3) i use the numeric index to pull only those answers from a specific form and that forms field id's.

In any case, I already tried your suggestion. If I manually enter the bad words into a list all works great, no issues, and life is good. However, if I pull the bad words from a table in a dB, then either all entires get scrubbed, or none get scrubbed.


____________________________________
Just Imagine.
 
If I leave it like this it works great:
Code:
<cfset badwordslist = "badword1,badword2,badword3,badword4">
<cfset badWordsstatus = 0>
<cfoutput>
  <cfloop index="FAListIndex" from="1340" to="1343">
    <cfset FAList = listappend(FAList,trim(FormAnswer))>
	<cfset FAList = Replace(FAList," ",",","ALL")>
	  <cfloop list="#FAList#" index="i" delimiters="|,">
	    <cfif findnocase(i,#badwordslist#)>
	      <cfset badWordsstatus = badWordsstatus + 1>
	    </cfif>			
         </cfloop>
    <cfset FAList = "">
  </cfloop>	
</cfoutput>

If I change from the manual list to a dB created list (via valuelist()) then it doesn't work:
Code:
QUERY:
<cfquery name="badwordscheck" datasource="#default_ds#">
SELECT RTRIM(BadWords) as BD
FROM BadWordsTable
</cfquery>

CODE:
<cfset badwordslist = valuelist(badwordscheck.BD)>
<cfset badWordsstatus = 0>
<cfoutput>
  <cfloop index="FAListIndex" from="1340" to="1343">
    <cfset FAList = listappend(FAList,trim(FormAnswer))>
	<cfset FAList = Replace(FAList," ",",","ALL")>
	  <cfloop list="#FAList#" index="i" delimiters="|,">
	    <cfif findnocase(i,#badwordslist#)>
	      <cfset badWordsstatus = badWordsstatus + 1>
	    </cfif>			
         </cfloop>
    <cfset FAList = "">
  </cfloop>	
</cfoutput>

What am I doing wrong? Thanks.


____________________________________
Just Imagine.
 
ok lets forget the over all process. if that is the only thing you change it would seem there are bad values in your value list.

what do you get when you output the value list?


Human beings, who are almost unique in having the ability to learn from the experience of others, are also remarkable for their apparent disinclination to do so.
-Douglas Adams (1952-2001)
 
When I output the value list, I get all the badwords in a comma delimeted list.

But this part is interesting: When all words kept getting scrubbed I outputted all results after every line to see what happens. What I noticed is that entries where no badwords are used still get scrubbed because the loop finds words that make up parts of the bad words.

For instance, if the bad word was: 'asp' but the entry had: 'as', then that word gets scrubbed.

This is what the result looks like:

valuelist: list1,list2,list3,lis4
FAList: list1,me,,list1,you,,let's,all,list1,now
i: list1
badWordsstatus: 1
FAList: list1,me,,list1,you,,let's,all,list1,now
i: me
badWordsstatus: 2
FAList: list1,me,,list1,you,,let's,all,list1,now
i: list1
badWordsstatus: 3
FAList: list1,me,,list1,you,,let's,all,list1,now
i: list1
badWordsstatus: 4
FAList: list1,me,,list1,you,,let's,all,list1,now
i: list1
badWordsstatus: 5
FAList: list1,me,,list1,you,,let's,all,list1,now
i: me
badWordsstatus: 6
FAList: list1,me,,list1,you,,let's,all,list1,now
i: list1
badWordsstatus: 7
FAList: list1,me,,list1,you,,let's,all,list1,now
i: list1
badWordsstatus: 8
FAList: list1,me,,list1,you,,let's,all,list1,now
i: list1
badWordsstatus: 9
FAList: list1,me,,list1,you,,let's,all,list1,now
i: me
badWordsstatus: 10
FAList: list1,me,,list1,you,,let's,all,list1,now
i: list1
badWordsstatus: 11
FAList: list1,me,,list1,you,,let's,all,list1,now
i: list1
badWordsstatus: 12
FAList: list1,me,,list1,you,,let's,all,list1,now
i: list1
badWordsstatus: 13
FAList: list1,me,,list1,you,,let's,all,list1,now
i: me
badWordsstatus: 14
FAList: list1,me,,list1,you,,let's,all,list1,now
i: list1
badWordsstatus: 15
FAList: list1,me,,list1,you,,let's,all,list1,now
i: list1
badWordsstatus: 16
FAList: on
i: on
badWordsstatus: 17
FAList: on
i: on
badWordsstatus: 18
FAList: on
i: on
badWordsstatus: 19
FAList: on
i: on
badWordsstatus: 20

-NOTICE THE 'I' HERE AND COMPARE WITH THE 'VALUELIST'
valuelist: list1,list2,list3,lis4
FAList: this,is,a,profane,test if,i,pass,then,we,succeeded if,not,,then,back,2,the,drawing,board
i: is
badWordsstatus: 1
FAList: this,is,a,profane,test if,i,pass,then,we,succeeded if,not,,then,back,2,the,drawing,board
i: a
badWordsstatus: 2
FAList: this,is,a,profane,test if,i,pass,then,we,succeeded if,not,,then,back,2,the,drawing,board
i: i
badWordsstatus: 3
FAList: this,is,a,profane,test if,i,pass,then,we,succeeded if,not,,then,back,2,the,drawing,board
i: is
badWordsstatus: 4
FAList: this,is,a,profane,test if,i,pass,then,we,succeeded if,not,,then,back,2,the,drawing,board
i: a
badWordsstatus: 5
FAList: this,is,a,profane,test if,i,pass,then,we,succeeded if,not,,then,back,2,the,drawing,board
i: i
badWordsstatus: 6
FAList: this,is,a,profane,test if,i,pass,then,we,succeeded if,not,,then,back,2,the,drawing,board
i: is
badWordsstatus: 7
FAList: this,is,a,profane,test if,i,pass,then,we,succeeded if,not,,then,back,2,the,drawing,board
i: a
badWordsstatus: 8
FAList: this,is,a,profane,test if,i,pass,then,we,succeeded if,not,,then,back,2,the,drawing,board
i: i
badWordsstatus: 9
FAList: this,is,a,profane,test if,i,pass,then,we,succeeded if,not,,then,back,2,the,drawing,board
i: is
badWordsstatus: 10
FAList: this,is,a,profane,test if,i,pass,then,we,succeeded if,not,,then,back,2,the,drawing,board
i: a
badWordsstatus: 11
FAList: this,is,a,profane,test if,i,pass,then,we,succeeded if,not,,then,back,2,the,drawing,board
i: i
badWordsstatus: 12
FAList: on
i: on
badWordsstatus: 13
FAList: on
i: on
badWordsstatus: 14
FAList: on
i: on
badWordsstatus: 15
FAList: on
i: on
badWordsstatus: 16



____________________________________
Just Imagine.
 
in that case try listFindNoCase and not findNoCase. which you should have used anyway, that's why you put it in a list. :)

<cfif listfindnocase(i,#badwordslist#)>


Human beings, who are almost unique in having the ability to learn from the experience of others, are also remarkable for their apparent disinclination to do so.
-Douglas Adams (1952-2001)
 
I tried that already. But when I do that, everything gets through.

I also tried: ListFind(), ListFindNoCase(), Find(), FindNoCase()




____________________________________
Just Imagine.
 
where does the pipe come from in your delimiter?

Human beings, who are almost unique in having the ability to learn from the experience of others, are also remarkable for their apparent disinclination to do so.
-Douglas Adams (1952-2001)
 
That is sooo weird, the values from your DB are coming all messed up, after you build the list from the DB with valueList() how long is the list?

Does anybody know if there are restrictions on the number of elements a list can have?

try clearing all the whitespaces in your list by treating it as a large String.

Code:
<cfset badwordslist = valuelist(badwordscheck.BD)>
[b]<cfset badwordslist = reReplaceNoCase(badwordslist," ","","ALL")>[/b]
<cfset badWordsstatus = 0>

see if you have more luck with that.....

grtfercho çB^]\..
"Imagination is more important than Knowledge" A. Einstein
-----------------------------------------------
 
bombboy, I am parsing each hard return of an entry with a pipe delimiter when the user hits SUBMIT. I don't need that pipe delimiter in the <cfloop list="#FAList#" index="i" delimiters="|,">, I just added it in there for heck of it.

grtfercho, currently there are about 35 bad words in the table (and i'm sure as time goes by more and more will be added). When I pull the words from the table I am using the RTRIM (as suggested by r937). When I output the list onto the screen, it all seems to be right. From my above post, valuelist: list1,list2,list3,lis4.

This is strange that when the values are listed via valuelist the scrub doesn't work, YET when I hardcode the list everything is right.


____________________________________
Just Imagine.
 
This is too strange I suggest you paste a big chunk of your code here because the problem doesn't seem to be in this part of the logic.
I'm thinking that there is some other line of code where values are getting messed up.
A list is nothing but a string with commas so all the rtrim,ltrim should work without problems.

Try to paste a bigger chunk of code with as much comments as you can so we can all analyze the code.

grtfercho çB^]\..
"Imagination is more important than Knowledge" A. Einstein
-----------------------------------------------
 
Here you go. This is my "entire" code. I have changed or taken out some code that has no relation to this.

This is driving me insane.

Code:
<!--- set up export dlimiter and text qualifier --->	
<cfset delimiter = chr(9)>

<!--- set up export filename and path --->
<cfset FileName="filename_#DateFormat(now(),'MMDDYYYY')#.txt">
<cfset FullPathName = "#getdirectoryfrompath(gettemplatepath())#files\#FileName#">

<!--- badwords query, table has only 35 words for now --->
<cfquery name="badwordscheck" datasource="#default_ds#">
SELECT RTRIM(BadWords) as BD
FROM BadWordsTable
</cfquery>

<!--- gets the user info --->
<cfquery name="getTheUser" datasource="#default_ds#">
SELECT DISTINCT User_ID, FirstName, LastName, FAns, FormField_ID, CreateDate AS timestamp
FROM   MyTable
WHERE  (Form_ID = #The_Form#)
ORDER BY U.User_ID, FA.FormField_ID
</cfquery>

<!--- create text file --->
<cffile action="write" file="#FullPathName#" output="FirstName#delimiter#MiddleName#delimiter#LastName#delimiter#answer1#delimiter#answer2#delimiter#answer3#delimiter#answer4" addnewline="Yes">

<table>
<cfoutput query="getTheUser" group="User_ID">
<tr>
<td></td>
    <!--- gets the answers from the table depending on the FormField_ID --->
	<cfoutput>
		<cfif FormField_ID is 1340>
		  <cfset answer1 = trim(FAns)>
		<cfelseif FormField_ID is 1341>
		  <cfset answer2 = Replace(FAns,chr(13)&chr(10),"|","ALL")>
		<cfelseif FormField_ID is 1342>
		  <cfif len(FAns) eq 0><cfset answer3 = "no"><cfelse><cfset answer3 = trim(FAns)></cfif> 
		<cfelseif FormField_ID is 1343>
		  <cfif len(FAns) eq 0><cfset answer4 = "off"><cfelse><cfset answer4 = trim(FAns)></cfif>			
		</cfif>	
	</cfoutput>
	
    <!--- <cfset badwordslist = "badwords1,badwords2,badwords3,badwords4,badwords5,badwords6,badwords7"> --->
	<!--- creates a list of the badwords from the table via 'valuelist()' --->
	<cfset badwordslist = valuelist(badwordscheck.BD)>
	<!--- sets badWordsstate to 0 intially --->
    <cfset badWordsstatus = 0>
    <cfoutput>
	  <cfloop index="FAListIndex" from="1340" to="1343">
	    <!--- creates a list for the FAns --->
		<cfset FAList = listappend(FAList,trim(FAns))>
		<!--- repalces all blank spaces with a comma --->
		<cfset FAList = Replace(FAList," ",",","ALL")>
		  <cfloop list="#FAList#" index="i" delimiters="|,">
		    <cfif listfindnocase(i,#badwordslist#)>
			  <!--- if badwords found, increment by one --->
			  <cfset badWordsstatus = badWordsstatus + 1>
			</cfif>			
		  </cfloop>
		<!--- sets the FA:ist back to blank so another userid's values can be set into a list and looped through --->
		<cfset FAList = "">
	  </cfloop>	
	</cfoutput>
	
	<cfif badWordsstatus EQ 0 and len(answer2) gt 0>
      <cffile action="append" file="#FullPathName#" output="#FirstName##delimiter##delimiter##LastName##delimiter##answer1##delimiter##answer2##delimiter##answer3##delimiter##answer4#" addnewline="Yes">
	  <cfset Status = "Sent">	  
    <cfelse>
      <cfset StatusDesc = "Failed:  bad words">
    </cfif>	
</cfoutput>
</table>
Done

<cfmail from="email@from.com" to="email@to.com" subject="Test">
<cfsilent>
  <cfmailparam file="#FullPathName#">
</cfsilent>
</cfmail>


____________________________________
Just Imagine.
 
This is interesting: When all words kept getting scrubbed I outputted all results after every line to see what happens. What I noticed is that entries where no badwords are used still get scrubbed because the loop finds words that make up parts of the bad words. So I took one word that causes the situation, 'MORON' and the code started working right. The 'ON' in MORON inteferred with answer choice of 'On'.

Now my question is, why would that happen? Shouldn't it look at the entire word to see if it matches a bad word? Why would an answer value 'On' get scrubbed if I have MORON as a bad word??

Any ideas??


____________________________________
Just Imagine.
 
Try this again

Change
Code:
 <cfset badwordslist = valuelist(badwordscheck.BD)>
    <!--- sets badWordsstate to 0 intially --->

to
Code:
 <cfset badwordslist = valuelist(badwordscheck.BD)>
    <!--- sets badWordsstate to 0 intially --->
<cfset badwordslist=replace(badwordslist," ","","ALL")>
purpose:Get rid of every space in the list so you ha ve a clean list to work with.

Get rid of every cfoutput with the exception of the outermost ( the one that starts <cfoutput cfoutput query="getTheUser" ....)

Check if this line
Code:
<cfset answer2 = Replace(FAns,chr(13)&chr(10),"|","ALL")>

is doing what is supposed to do, I'm not sure this is working, but I don't have CFML access here so I cannot try and test it.


This is too getting really, really long for such a small thing......

grtfercho çB^]\..
"Imagination is more important than Knowledge" A. Einstein
-----------------------------------------------
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top