Hi there,
Well after a short period of a client's form being spammed, I decided to look into a way of blocking certain words from being entered into the comments box using a simple validation, ie. checking for a word and then refusing to submit the information forward, thus stopping the computer program in it's tracks.
It's incredibly simple and does not even use a captcha system, mostly because the client felt that enquiries would not be sent due to people having to "bother" with entering the required code.
So, I simply dropped in an if statement which checked for certain words which seemed to be appearing within the enquiry emails, although I seem to have stopped my code from working entirely and I'm not quite sure how, mainly because this site was built a year or so back and I haven't used the validation code since.
The "offending" code is shown below, with the entire javascript following it.
Code:
if(frm.elements[comments].value == 'nude' || frm.elements[comments].value == 'viagra') {
isValid = false;
strErrMsg += "Your comments are not appropriate\n";
} Code:
function validate(frm,tel,email,comments,nonBlank) {
var isValid = true;
var someBlank = false;
var strErrMsg = "The following errors occurred with your submission :\t\n\n";
var alphaChars = "abcdefghijklmnopqrstuvwxyz";
alphaArray = new Array();
for (var i=0; i<alphaChars.length; i++) {
alphaArray[i] = alphaChars.charAt(i);
}
if (tel != '')
{
if(frm.elements[tel].value != '') {
for (var i=0; i<alphaArray.length; i++) {
if(String(frm.elements[tel].value).indexOf(alphaArray[i]) != -1) {
isValid = false;
}
}
if (isValid == false) {
strErrMsg += "The telephone number you entered is not a number\n";
}
}
}
if (email != '')
{
if(frm.elements[email].value != '') {
if(frm.elements[email].value.indexOf('@') == -1 || frm.elements[email].value.indexOf('.') == -1 || frm.elements[email].value.indexOf(' ') != -1) {
isValid = false;
strErrMsg += "You have not supplied a valid email address\n";
}
}
}
if(frm.elements[comments].value == 'nude' || frm.elements[comments].value == 'viagra') {
isValid = false;
strErrMsg += "Your comments are not appropriate\n";
}
var nonBlankElements = nonBlank.split(",");
for(var x=0;x<nonBlankElements.length;x++) {
if(frm.elements[nonBlankElements[x]].value == '') {
someBlank = true;
}
}
if(someBlank == true) {
isValid = false;
strErrMsg += "You have not filled in all the required (*) fields";
}
if(isValid == false) {
alert(strErrMsg);
}
return isValid;
} If someone could reply back to me as soon as possible I would be most grateful as the website is currently live.
Thank you in advance!

Andrew.