3 * GForge Project Management Facility
5 * Copyright 2002 GForge, LLC
8 * This file is part of GForge.
10 * GForge is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * GForge 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
21 * along with GForge; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 US
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);