1: <?php
2:
3: /**
4: * This file contains the cHTMLTextbox 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: * cHTMLTextbox class represents a textbox.
21: *
22: * @package Core
23: * @subpackage GUI_HTML
24: */
25: class cHTMLTextbox extends cHTMLFormElement {
26:
27: /**
28: * Constructor.
29: * Creates an HTML text box.
30: *
31: * If no additional parameters are specified, the
32: * default width is 20 units.
33: *
34: * @param string $name
35: * Name of the element
36: * @param string $initvalue [optional]
37: * Initial value of the box
38: * @param int $width [optional]
39: * width of the text box
40: * @param int $maxlength [optional]
41: * maximum input length of the box
42: * @param string $id [optional]
43: * ID of the element
44: * @param string $disabled [optional]
45: * Item disabled flag (non-empty to set disabled)
46: * @param string $tabindex [optional]
47: * Tab index for form elements
48: * @param string $accesskey [optional]
49: * Key to access the field
50: * @param string $class [optional]
51: * the class of this element
52: */
53: public function __construct(
54: $name, $initvalue = '', $width = '', $maxlength = '', $id = '',
55: $disabled = false, $tabindex = NULL, $accesskey = '', $class = ''
56: ) {
57:
58: parent::__construct($name, $id, $disabled, $tabindex, $accesskey);
59:
60: $this->_tag = 'input';
61: $this->_contentlessTag = true;
62: $this->setValue($initvalue);
63:
64: $this->setWidth($width);
65: $this->setMaxLength($maxlength);
66:
67: $this->updateAttribute('type', 'text');
68: $this->setClass($class);
69: }
70:
71: /**
72: * Sets the width of the text box.
73: *
74: * @param int $width
75: * width of the text box
76: * @return cHTMLTextbox
77: * $this for chaining
78: */
79: public function setWidth($width) {
80: $width = intval($width);
81:
82: if ($width <= 0) {
83: $width = 50;
84: }
85:
86: return $this->updateAttribute('size', $width);
87: }
88:
89: /**
90: * Sets the maximum input length of the text box.
91: *
92: * @param int $maxlen
93: * maximum input length
94: * @return cHTMLTextbox
95: * $this for chaining
96: */
97: public function setMaxLength($maxlen) {
98: $maxlen = intval($maxlen);
99:
100: if ($maxlen <= 0) {
101: return $this->removeAttribute('maxlength');
102: } else {
103: return $this->updateAttribute('maxlength', $maxlen);
104: }
105: }
106:
107: /**
108: * Sets the initial value of the text box.
109: *
110: * @param string $value
111: * Initial value
112: * @return cHTMLTextbox
113: * $this for chaining
114: */
115: public function setValue($value) {
116: return $this->updateAttribute('value', $value);
117: }
118:
119: }
120: