PDA

View Full Version : filtering form field results.


Mhtml
09-24-2002, 04:01 AM
How can I filter the results of a form field?

I want to stop people from putting bad links in my link section, so I need to able to stop the page from processing the link addition if certain words are detected.

allida77
09-24-2002, 04:08 AM
something like

If InStr(Request.Form("txtURL"),"badurltext",VBTextCompare)
Response.Write("Please enter a valid URL")
End If

InStr() (http://www.devguru.com/Technologies/vbscript/quickref/instr.html)

Mhtml
09-24-2002, 04:25 AM
how can I have multiple words? do I just have spaces or use commas?

allida77
09-24-2002, 04:35 AM
I tend to overuse arrays but anyways:





dim aBadWords(2)
aBadWords = ("fudge","crap",darn")

For Each word In aBadWords
If InStr(Request.Form("txtURL"),word,VBTextCompare)
booBadWrd = true
End If
Next

If booBadWrd = true Then
Response.Write("BadURL")
End If



Did not test but I think it should work.:D

glenngv
09-24-2002, 04:36 AM
txtURL = request.form("txtURL")
arrBad = array("bad1", "bad2", "bad3") 'put bad URL text here
for i = 0 to ubound(arrBad)
If InStr(txtURL,arrBad(i),VBTextCompare)
Response.Write("Please enter a valid URL")
exit for
End If
next

Mhtml
09-24-2002, 05:09 AM
I keep getting errors, I have fixed the things that the error had a problem with but I've no idea about this one..

Error Type:
Microsoft VBScript runtime (0x800A000D)
Type mismatch: '[string: "bad1"]'
/projectodyssey/linkinsert.asp, line 5

<%dim txtURL, arrBad
txtURL = request.form("linkname")
arrBad = array("bad1", "bad2", "bad3") 'put bad URL text here
for i = 0 to ubound(arrBad)
If InStr(txtURL , arrBad(i),VBTextCompare) then
Response.Redirect("illegal.asp")
exit for
End If
next

%>

allida77
09-24-2002, 06:17 AM
take out the VBTextCompare.

glenngv
09-24-2002, 07:15 AM
try this:

If InStr(1, txtURL , arrBad(i),VBTextCompare)


first argument is actually optional but without it, it returns type mismatch error. dont know why. Better to put it anyway. BTW, 1 means the position where to search the string

Mhtml
09-24-2002, 07:21 AM
Ok I have it working perfectly, and I just created the page you get redirected to if bad words are found. What I need is for you to tell me if you think that what the page says is fair.

PS: The email script for the page is not yet enabled...