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