required.php 1.6 KB
Newer Older
1
2
<?php
/**
3
 * This program is part of Pieforms
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
 *
19
20
 * @package    pieform
 * @subpackage rule
21
22
 * @author     Nigel McNie <nigel@catalyst.net.nz>
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL
23
 * @copyright  (C) 2006 Catalyst IT Ltd http://catalyst.net.nz
24
25
26
 *
 */

27
28
29
/**
 * Checks whether the field has been specified.
 *
30
31
32
33
 * @param Pieform $form   The form the rule is being applied to
 * @param string $field   The field to check
 * @param array  $element The element to check
 * @return string         The error message, if the value is invalid.
34
 */
35
function pieform_rule_required(Pieform $form, $value, $element) {
36
37
    $function = 'form_is_empty_' . $element['type'];
    if (function_exists($function)) {
38
39
        if ($function($value, $element)) {
            return $form->i18n('required');
40
41
42
43
        }
        return;
    }

44
45
    if ($value == '') {
        return $form->i18n('required');
46
47
48
49
    }
}

?>