3 * FusionForge field validator
5 * Copyright 2002, GForge, LLC
7 * This file is part of FusionForge. FusionForge is free software;
8 * you can redistribute it and/or modify it under the terms of the
9 * GNU General Public License as published by the Free Software
10 * Foundation; either version 2 of the Licence, or (at your option)
13 * FusionForge is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License along
19 * with FusionForge; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 * This class is a simple utility to validate fields
28 * $v = new Validator();
29 * $v->check($summary, "summary");
30 * $v->check($detail, "detail");
31 * if (!$v->isClean()) {
32 * print $v->formErrorMsg("The following fields were null:");
40 * Checks to see if a field is null; if so, the field name is added to an internal array
42 * @param field - a variable to check for null
43 * @param name - the variable name
45 function check($field, $name) {
47 $this->badfields[] = $name;
52 * Returns true if no null fields have been checked so far
54 * @return boolean - True if there are no null fields so far
57 return count($this->badfields) == 0;
61 * Returns an error message which contains the null field names which have been checked
63 * @param string $preamble - A string with which to start the error message
64 * @return string - A complete error message
66 function formErrorMsg($preamble) {
67 foreach ($this->badfields as $field) {
68 $preamble = $preamble.$field.",";
70 return substr($preamble, 0, strlen($preamble)-1);
76 // c-file-style: "bsd"