1: <?php
2:
3: /**
4: * This file contains the cHTMLButton class.
5: *
6: * @package Core
7: * @subpackage GUI_HTML
8: *
9: * @author Simon Sprankel
10: * @copyright four for business AG <www.4fb.de>
11: * @license http://www.contenido.org/license/LIZENZ.txt
12: * @link http://www.4fb.de
13: * @link http://www.contenido.org
14: */
15:
16: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
17:
18: /**
19: * cHTMLButton class represents a button.
20: *
21: * @package Core
22: * @subpackage GUI_HTML
23: */
24: class cHTMLButton extends cHTMLFormElement {
25:
26: /**
27: * Constructor to create an instance of this class.
28: *
29: * Creates an HTML button.
30: *
31: * Creates a submit button by default, can be changed
32: * using setMode.
33: *
34: * @param string $name
35: * Name of the element
36: * @param string $title [optional]
37: * Title of the button
38: * @param string $id [optional]
39: * ID of the element
40: * @param string $disabled [optional]
41: * Item disabled flag (non-empty to set disabled)
42: * @param string $tabindex [optional]
43: * Tab index for form elements
44: * @param string $accesskey [optional]
45: * Key to access the field
46: * @param string $mode [optional]
47: * Mode of button
48: * @param string $class [optional]
49: * the class of this element
50: */
51: public function __construct($name, $title = '', $id = '', $disabled = false, $tabindex = NULL, $accesskey = '', $mode = 'submit', $class = '') {
52: parent::__construct($name, $id, $disabled, $tabindex, $accesskey);
53: $this->_tag = 'input';
54: $this->_contentlessTag = true;
55: $this->setTitle($title);
56: $this->setMode($mode);
57: $this->setClass($class);
58: }
59:
60: /**
61: * Sets the title (caption) for the button
62: *
63: * @param string $title
64: * The title to set
65: * @return cHTMLButton
66: * $this for chaining
67: */
68: public function setTitle($title) {
69: $this->updateAttribute('value', $title);
70:
71: return $this;
72: }
73:
74: /**
75: * Sets the mode (submit or reset) for the button
76: *
77: * @param string $mode
78: * Either 'submit', 'reset' or 'image'.
79: * @return cHTMLButton
80: * $this for chaining
81: */
82: public function setMode($mode) {
83: $modes = array(
84: 'submit',
85: 'reset',
86: 'image',
87: 'button'
88: );
89: if (in_array($mode, $modes)) {
90: $this->updateAttribute('type', $mode);
91: }
92:
93: return $this;
94: }
95:
96: /**
97: * Set the image src if mode type is "image"
98: *
99: * @param string $src
100: * Image path.
101: * @return cHTMLButton
102: * $this for chaining
103: */
104: public function setImageSource($src) {
105: $this->setMode('image');
106: return $this->updateAttribute('src', $src);
107: }
108:
109: }
110: