3 * FusionForge field validator
5 * Copyright 2002, GForge, LLC
7 * This file is part of FusionForge.
9 * FusionForge is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published
11 * by the Free Software Foundation; either version 2 of the License,
12 * or (at your option) any later version.
14 * FusionForge is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with FusionForge; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
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"