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