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, $initvalue = '', $width = '', $maxlength = '', $id = '', $disabled = false, $tabindex = null, $accesskey = '', $class = '') {
45: parent::__construct($name, $id, $disabled, $tabindex, $accesskey);
46:
47: $this->_tag = 'input';
48: $this->_contentlessTag = true;
49: $this->setValue($initvalue);
50:
51: $this->setWidth($width);
52: $this->setMaxLength($maxlength);
53:
54: $this->updateAttribute('type', 'text');
55: $this->setClass($class);
56: }
57:
58: /**
59: * Sets the width of the text box.
60: *
61: * @param int $width width of the text box
62: * @return cHTMLTextbox $this
63: */
64: public function setWidth($width) {
65: $width = intval($width);
66:
67: if ($width <= 0) {
68: $width = 50;
69: }
70:
71: return $this->updateAttribute('size', $width);
72: }
73:
74: /**
75: * Sets the maximum input length of the text box.
76: *
77: * @param int $maxlen maximum input length
78: * @return cHTMLTextbox $this
79: */
80: public function setMaxLength($maxlen) {
81: $maxlen = intval($maxlen);
82:
83: if ($maxlen <= 0) {
84: return $this->removeAttribute('maxlength');
85: } else {
86: return $this->updateAttribute('maxlength', $maxlen);
87: }
88: }
89:
90: /**
91: * Sets the initial value of the text box.
92: *
93: * @param string $value Initial value
94: * @return cHTMLTextbox $this
95: */
96: public function setValue($value) {
97: return $this->updateAttribute('value', $value);
98: }
99:
100: }
101: