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.
11 * FusionForge is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published
13 * by the Free Software Foundation; either version 2 of the License,
14 * or (at your option) any later version.
16 * FusionForge is distributed in the hope that it will be useful, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with FusionForge; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
28 * This class is a simple utility to validate fields
32 * $v = new Validator();
33 * $v->check($summary, "summary");
34 * $v->check($detail, "detail");
35 * if (!$v->isClean()) {
36 * print $v->formErrorMsg("The following fields were null:");
44 * Checks to see if a field is null; if so, the field name is added to an internal array
46 * @param field - a variable to check for null
47 * @param name - the variable name
49 function check($field, $name) {
51 $this->badfields[] = $name;
56 * Returns true if no null fields have been checked so far
58 * @return boolean - True if there are no null fields so far
61 return count($this->badfields) == 0;
65 * Returns an error message which contains the null field names which have been checked
67 * @param preamble string - A string with which to start the error message
68 * @return string - A complete error message
70 function formErrorMsg($preamble) {
71 foreach ($this->badfields as $field) {
72 $preamble = $preamble.$field.",";
74 return substr($preamble, 0, strlen($preamble)-1);
80 // c-file-style: "bsd"