3 * FusionForge project manager
5 * Copyright 1999-2000, Tim Perdue/Sourceforge
6 * Copyright 2002, Tim Perdue/GForge, LLC
8 * This file is part of FusionForge.
10 * FusionForge is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published
12 * by the Free Software Foundation; either version 2 of the License,
13 * or (at your option) any later version.
15 * FusionForge is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with FusionForge; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
27 * This class is a simple utility to validate fields
31 * $v = new Validator();
32 * $v->check($summary, "summary");
33 * $v->check($detail, "detail");
34 * if (!$v->isClean()) {
35 * print $v->formErrorMsg("The following fields were null:");
43 * Checks to see if a field is null; if so, the field name is added to an internal array
45 * @param field - a variable to check for null
46 * @param name - the variable name
48 function check($field, $name) {
50 $this->badfields[] = $name;
55 * Returns true if no null fields have been checked so far
57 * @return boolean - True if there are no null fields so far
60 return count($this->badfields) == 0;
64 * Returns an error message which contains the null field names which have been checked
66 * @param preamble string - A string with which to start the error message
67 * @return string - A complete error message
69 function formErrorMsg($preamble) {
70 foreach ($this->badfields as $field) {
71 $preamble = $preamble.$field.",";
73 return substr($preamble, 0, strlen($preamble)-1);
79 // c-file-style: "bsd"