There are many ways to do this but here's one. You can build a function that checks a variable for bad words and returns false if there are any:
function checkBadWords($text) {
$badWords = array('badword1', 'badword2', 'badword3');
foreach ($badWords as $badWord) {
if (ereg($badWord, $text)) {
return false;
}
}
return true;
}
You can call the funtion in your error checking like this:
if (!checkBadWords($message)) {
// re-print the form
}
So if the function returns false then you want to re-print the form. Otherwise you process it.