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