NogDog wrote:Any white-list filtering and/or validation would come before your call to $CommentDAO->addComment($_POST);.
And after (probably immediately after, since you'd probably want to add a message to the errors array that you later count) your checks to see if the user has filled in those fields. (Incidentally, for both that and the earlier checks, you might find using [man]empty[/man] to be a more concise than [man]isset[/man] and [man]count[/man]).
Validating the name will mean checking [font=monospace]$POST['naam'][/font] again. Which still might not be set. That would cause trouble when you try to do any more validation. There are two ways of dealing with the situation:
1)
if(isset($_POST['naam']) && $_POST['naam'] != "")
{
// validate the name
}
which means either doing the same test twice, or doing the test once and storing the result in a variable, or doing name validation at the same time that you check that it's not empty (before going on to check the message) - putting the extra validation tests into else branches ("if($_POST['naam'] is empty, complain about that, else check it against the whitelst").
2)
Start by setting unset POST variables to have empty values.
if(!isset($_POST['naam']))
{
$_POST['naam'] = "";
}
Then the test to see if the variable is empty can just be [font=monospace]if($_POST['naam'] == "")[/font] and other validation tests can be made without worrying about whether the variable is set.
Since there are a bunch of variables that need to be non-empty, the above snipped would need to be repeated. If you're repeating stuff then that's a hint that you're doing something wrong (repeating stuff should be the computer's job). The fact is that you can set default (empty, and therefore invalid) values for name, message and the rest in one line:
$_POST += array('naam' => '', 'bericht' => '' ....);
(See the array + operator.) Do that before you start any of your validation and you won't have to worry later if the variables you're validating are set or not (and the repetition that still exists in that line can be eliminated by using the [man]array_fill_keys[/man] function).