required.php 1.71 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<?php
/**
 * This program is part of Mahara
 *
 *  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
 *
 * @package    mahara
20
 * @subpackage form-rule
21
22
23
24
25
26
27
28
 * @author     Nigel McNie <nigel@catalyst.net.nz>
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL
 * @copyright  (C) 2006,2007 Catalyst IT Ltd http://catalyst.net.nz
 *
 */

defined('INTERNAL') || die();

29
30
31
/**
 * Checks whether the field has been specified.
 *
32
 * @param Form $form        The form the rule is being applied to
33
 * @param string $field     The field to check
34
 * @param array  $element   The element to check
35
36
 * @return string           The error message, if the value is invalid.
 */
37
function form_rule_required(Form $form, $value, $element) {
38
    // The array test is for using the "required" rule on file elements
39
40
    $function = 'form_is_empty_' . $element['type'];
    if (function_exists($function)) {
41
42
        if ($function($value, $element)) {
            return $form->i18n('required');
43
44
45
46
        }
        return;
    }

47
48
    if ($value == '') {
        return $form->i18n('required');
49
50
51
52
    }
}

?>