required.php 1.89 KB
Newer Older
1
2
<?php
/**
3
4
 * Pieforms: Advanced web forms made easy
 * Copyright (C) 2006-2008 Catalyst IT Ltd (http://www.catalyst.net.nz)
5
 *
6
7
8
9
 * 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 3 of the License, or
 * (at your option) any later version.
10
 *
11
12
13
14
 * 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.
15
 *
16
17
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18
 *
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-2008 Catalyst IT Ltd http://catalyst.net.nz
24
25
26
 *
 */

27
28
29
/**
 * Checks whether the field has been specified.
 *
30
 * @param Pieform $form    The form the rule is being applied to
Nigel McNie's avatar
Nigel McNie committed
31
 * @param string  $value   The value of the field
32
33
 * @param array   $element The element to check
 * @param string  $check   Whether to check the element
34
 * @return string         The error message, if the value is invalid.
35
 */
36
37
function pieform_rule_required(Pieform $form, $value, $element, $check) {/*{{{*/
    if ($check && ($value == '' || $value == array())) {
Nigel McNie's avatar
Nigel McNie committed
38
        return $form->i18n('rule', 'required', 'required', $element);
39
    }
40
}/*}}}*/
41

42
function pieform_rule_required_i18n() {/*{{{*/
Nigel McNie's avatar
Nigel McNie committed
43
44
45
    return array(
        'en.utf8' => array(
            'required' => 'This field is required'
46
        ),
47
        'de.utf8' => array(
48
49
            'required' => 'Das Feld ist erforderlich'
        ),
50
51
52
        'fr.utf8' => array(
            'required' => 'Ce champ est obligatoire'
        ),
Nigel McNie's avatar
Nigel McNie committed
53
    );
54
}/*}}}*/
Nigel McNie's avatar
Nigel McNie committed
55

56
?>