Subversion Repositories Applications.papyrus

Rev

Rev 1087 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
320 jpm 1
<?php
2
/* vim: set expandtab tabstop=4 shiftwidth=4: */
3
// +----------------------------------------------------------------------+
4
// | PHP Version 4                                                        |
5
// +----------------------------------------------------------------------+
6
// | Copyright (c) 1997-2003 The PHP Group                                |
7
// +----------------------------------------------------------------------+
8
// | This source file is subject to version 2.0 of the PHP license,       |
9
// | that is bundled with this package in the file LICENSE, and is        |
10
// | available at through the world-wide-web at                           |
11
// | http://www.php.net/license/2_02.txt.                                 |
12
// | If you did not receive a copy of the PHP license and are unable to   |
13
// | obtain it through the world-wide-web, please send a note to          |
14
// | license@php.net so we can mail you a copy immediately.               |
15
// +----------------------------------------------------------------------+
16
// | Authors: Alexey Borzov <avb@php.net>                                 |
17
// +----------------------------------------------------------------------+
18
//
443 ddelon 19
// $Id: xbutton.php,v 1.2 2005-09-20 17:01:22 ddelon Exp $
320 jpm 20
 
21
require_once 'HTML/QuickForm/element.php';
22
 
23
/**
24
 * Class for HTML 4.0 <button> element
25
 *
26
 * @author  Alexey Borzov <avb@php.net>
27
 * @since   3.2.3
28
 * @access  public
29
 */
30
class HTML_QuickForm_xbutton extends HTML_QuickForm_element
31
{
32
   /**
33
    * Contents of the <button> tag
34
    * @var      string
35
    * @access   private
36
    */
37
    var $_content;
38
 
39
   /**
40
    * Class constructor
41
    *
42
    * @param    string  Button name
43
    * @param    string  Button content (HTML to add between <button></button> tags)
44
    * @param    mixed   Either a typical HTML attribute string or an associative array
45
    * @access   public
46
    */
47
    function HTML_QuickForm_xbutton($elementName = null, $elementContent = null, $attributes = null)
48
    {
49
        $this->HTML_QuickForm_element($elementName, null, $attributes);
50
        $this->setContent($elementContent);
51
        $this->setPersistantFreeze(false);
52
        $this->_type = 'xbutton';
53
    }
54
 
55
 
56
    function toHtml()
57
    {
58
        return '<button' . $this->getAttributes(true) . '>' . $this->_content . '</button>';
59
    }
60
 
61
 
62
    function getFrozenHtml()
63
    {
64
        return $this->toHtml();
65
    }
66
 
67
 
68
    function freeze()
69
    {
70
        return false;
71
    }
72
 
73
 
74
    function setName($name)
75
    {
76
        $this->updateAttributes(array(
77
            'name' => $name
78
        ));
79
    }
80
 
81
 
82
    function getName()
83
    {
84
        return $this->getAttribute('name');
85
    }
86
 
87
 
88
    function setValue($value)
89
    {
90
        $this->updateAttributes(array(
91
            'value' => $value
92
        ));
93
    }
94
 
95
 
96
    function getValue()
97
    {
98
        return $this->getAttribute('value');
99
    }
100
 
101
 
102
   /**
103
    * Sets the contents of the button element
104
    *
105
    * @param    string  Button content (HTML to add between <button></button> tags)
106
    */
107
    function setContent($content)
108
    {
109
        $this->_content = $content;
110
    }
111
 
112
 
113
    function onQuickFormEvent($event, $arg, &$caller)
114
    {
115
        if ('updateValue' != $event) {
116
            return parent::onQuickFormEvent($event, $arg, $caller);
117
        } else {
118
            $value = $this->_findValue($caller->_constantValues);
119
            if (null === $value) {
120
                $value = $this->_findValue($caller->_defaultValues);
121
            }
122
            if (null !== $value) {
123
                $this->setValue($value);
124
            }
125
        }
126
        return true;
127
    }
128
 
129
 
130
   /**
131
    * Returns a 'safe' element's value
132
    *
133
    * The value is only returned if the button's type is "submit" and if this
134
    * particlular button was clicked
135
    */
136
    function exportValue(&$submitValues, $assoc = false)
137
    {
138
        if ('submit' == $this->getAttribute('type')) {
139
            return $this->_prepareValue($this->_findValue($submitValues), $assoc);
140
        } else {
141
            return null;
142
        }
143
    }
144
}
145
?>