Forum Moderators: open
I've got a free classifed ads service and it's becoming to be hardly spammed. Everyday (some days, more than once) I must connect trought FTP, downlad the flat text files with the ads, delete the spam messages and upload the files again. Awesome.
So I'm looking for a free javascript to block some words on the text area of the submission form.
What I get now is this:
(It does nothing with the form and I suspect the filter only will work if the textarea matchs exactly within the forbidden words)
<HTML>
<HEAD>
<script language="JavaScript1.2">
var forbidden=new Array()
forbidden[0]="obviously"
forbidden[1]="I will"
forbidden[2]="not"
forbidden[3]="put"
forbidden[4]="here"
forbidden[5]="any"
forbidden[6]="strong"
forbidden[7]="word"
var testresults
function checktext(){
var invalidcheck=0;
var str=document.myform.textarea.value
if (str==forbidden[i])
invalidcheck=1
if (invalidcheck!=1)
testresults=true
else{
alert("Sorry... some words of your ad are not allowed on this site")
testresults=false
}
return (testresults)
}
</script>
<script>
function checktextads(){
if (document.layers¦¦document.getElementById¦¦document.all)
return checktext()
else
return true
}
</script>
</HEAD>
<BODY>
<FORM NAME="myform" ACTION="cgi-bin/classifieds/update.pl" METHOD="post">
<TEXTAREA NAME="textarea" COLS="40" ROWS="5"></TEXTAREA>
<INPUT TYPE="submit" onClick="return checktextads()">
</FORM>
</BODY>
</HTML>
Can anyone help me?
Thanks in advance.
<SCRIPT type="text/javascript">var forbidden = new Array ("obviously", "I will", "not", "put", "here", "any", "strong", "word");
function checkForm (form){
var input = form.textarea.value;
var fail = false;
for (var i=0; i < forbidden.length; i++) {
badWord = forbidden[i];
if (input.indexOf(badWord)!= -1) {
fail = true;
break;
}
}
if (fail) {
// error message
return false;
}
return true;
}</SCRIPT>
<FORM ... onSubmit="return checkForm(this);">
<TEXTAREA NAME="textarea" COLS="40" ROWS="5"></TEXTAREA>
<INPUT TYPE="submit">
</FORM>
Works fine.
Something like
<SCRIPT type="text/javascript">
var forbidden = new Array ("v[!i1]agra", "xen[!i1]c[o0@]l", "c[i!1]al[i!1]s", "put", "here", "any", "strong", "word");
function checkForm (form){
var input = form.textarea.value;
var fail = false;
for (var i=0; i < forbidden.length; i++) {
Regex=eval('/'+forbidden[i]+'/i');
if (Regex.test(input)){
fail = true; break;
}
}
if (fail) {
alert("hey, you can't put that here!")
return false; }
return true;
}
</SCRIPT>
<FORM name="myform" method="post" action="" onSubmit="return checkForm(this);">
<TEXTAREA NAME="textarea" COLS="40" ROWS="5"></TEXTAREA>
<INPUT TYPE="submit">
</FORM>
However, since such folks are already relegated to the boundaries of society, they will probably not be deterred by such screen-door security.
ajkimoto