submitcancel.php 2.59 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 element
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
 *
 */

/**
 * Renders a submit and cancel button
 *
30
 * @param Pieform  $form    The form to render the element for
Nigel McNie's avatar
Nigel McNie committed
31
 * @param array    $element The element to render
32
 * @return string           The HTML for the element
33
 */
Nigel McNie's avatar
Nigel McNie committed
34
35
36
37
38
function pieform_element_submitcancel(Pieform $form, $element) {
    if (!isset($element['value']) || !is_array($element['value']) || count($element['value']) != 2) {
        throw new PieformException('The submitcancel element "' . $element['name']
            . '" must have a two element array for its value');
    }
39
40
    $form->include_plugin('element', 'submit');
    $form->include_plugin('element', 'cancel');
41
42
43
44
    $submitelement = $element;
    $submitelement['value'] = $element['value'][0];
    $cancelelement = $element;
    $cancelelement['value'] = $element['value'][1];
45
46
47
48
49
50
51
52
53
54
55
56
    if (isset($element['confirm']) && isset($element['confirm'][0])) {
        $submitelement['confirm'] = $element['confirm'][0];
    }
    else {
        unset($submitelement['confirm']);
    }
    if (isset($element['confirm']) && isset($element['confirm'][1])) {
        $cancelelement['confirm'] = $element['confirm'][1];
    }
    else {
        unset($cancelelement['confirm']);
    }
Nigel McNie's avatar
Nigel McNie committed
57
    return pieform_element_submit($form, $submitelement) . ' ' . pieform_element_cancel($form, $cancelelement);
58
59
}

Nigel McNie's avatar
Nigel McNie committed
60
61
function pieform_element_submitcancel_set_attributes($element) {
    $element['submitelement'] = true;
62
63
64
    return $element;
}

Nigel McNie's avatar
Nigel McNie committed
65
66
67
68
69
70
71
72
73
function pieform_element_submitcancel_get_value(Pieform $form, $element) {
    if (is_array($element['value'])) {
        return $element['value'][0];
    }
    else {
        return $element['value'];
    }
}

74
?>