1: <?php
2:
3: /**
4: * This file contains the cHTMLFormElement class.
5: *
6: * @package Core
7: * @subpackage GUI_HTML
8: * @version SVN Revision $Rev:$
9: *
10: * @author Simon Sprankel
11: * @copyright four for business AG <www.4fb.de>
12: * @license http://www.contenido.org/license/LIZENZ.txt
13: * @link http://www.4fb.de
14: * @link http://www.contenido.org
15: */
16:
17: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
18:
19: /**
20: * cHTMLFormElement class represents a form element.
21: *
22: * @package Core
23: * @subpackage GUI_HTML
24: */
25: class cHTMLFormElement extends cHTML {
26:
27: /**
28: * Constructor.
29: * This is a generic form element, where
30: * specific elements should be inherited from this class.
31: *
32: * @todo remove overfluous param class
33: * @param string $name [optional]
34: * Name of the element
35: * @param string $id [optional]
36: * ID of the element
37: * @param string $disabled [optional]
38: * Item disabled flag (non-empty to set disabled)
39: * @param string $tabindex [optional]
40: * Tab index for form elements
41: * @param string $accesskey [optional]
42: * Key to access the field
43: * @param string $class [optional]
44: * CSS class name to set
45: */
46: public function __construct(
47: $name = '', $id = '', $disabled = '', $tabindex = '', $accesskey = '',
48: $class = 'text_medium', $class = ''
49: ) {
50:
51: parent::__construct();
52:
53: $this->updateAttribute('name', $name);
54:
55: if (is_string($id) && !empty($id)) {
56: $this->updateAttribute('id', $id);
57: }
58:
59: $this->_tag = 'input';
60:
61: $this->setClass($class);
62: $this->setDisabled($disabled);
63: $this->setTabindex($tabindex);
64: $this->setAccessKey($accesskey);
65:
66: }
67:
68: /**
69: * Sets the "disabled" attribute of an element.
70: * User Agents
71: * usually are showing the element as "greyed-out".
72: *
73: * Example:
74: * $obj->setDisabled('disabled');
75: * $obj->setDisabled('');
76: *
77: * The first example sets the disabled flag, the second one
78: * removes the disabled flag.
79: *
80: * @param string $disabled
81: * Sets the disabled-flag if non-empty
82: * @return cHTMLFormElement
83: * $this for chaining
84: */
85: public function setDisabled($disabled) {
86: if (empty($disabled)) {
87: $this->removeAttribute('disabled');
88: } else {
89: $this->updateAttribute('disabled', 'disabled');
90: }
91:
92: return $this;
93: }
94:
95: /**
96: * Sets the tab index for this element.
97: * The tab
98: * index needs to be numeric, bigger than 0 and smaller than 32767.
99: *
100: * @param int $tabindex
101: * Desired tab index
102: * @return cHTMLFormElement
103: * $this for chaining
104: */
105: public function setTabindex($tabindex) {
106: if (is_numeric($tabindex) && $tabindex >= 0 && $tabindex <= 32767) {
107: $this->updateAttribute('tabindex', $tabindex);
108: }
109:
110: return $this;
111: }
112:
113: /**
114: * Sets the access key for this element.
115: *
116: * @param string $accesskey
117: * The length of the access key. May be A-Z and 0-9.
118: * @return cHTMLFormElement
119: * $this for chaining
120: */
121: public function setAccessKey($accesskey) {
122: if ((strlen($accesskey) == 1) && cString::isAlphanumeric($accesskey)) {
123: $this->updateAttribute('accesskey', $accesskey);
124: } else {
125: $this->removeAttribute('accesskey');
126: }
127:
128: return $this;
129: }
130:
131: }
132: