adding some strings
[moodle-linuxchix.git] / lib / pear / HTML / QuickForm / input.php
blobf182e7e4dd150e0cd0d467e73b8f14a8c743c13e
1 <?php
2 /* vim: set expandtab tabstop=4 shiftwidth=4: */
3 // +----------------------------------------------------------------------+
4 // | PHP version 4.0 |
5 // +----------------------------------------------------------------------+
6 // | Copyright (c) 1997, 1998, 1999, 2000, 2001 The PHP Group |
7 // +----------------------------------------------------------------------+
8 // | This source file is subject to version 2.0 of the PHP license, |
9 // | that is bundled with this package in the file LICENSE, and is |
10 // | available at through the world-wide-web at |
11 // | http://www.php.net/license/2_02.txt. |
12 // | If you did not receive a copy of the PHP license and are unable to |
13 // | obtain it through the world-wide-web, please send a note to |
14 // | license@php.net so we can mail you a copy immediately. |
15 // +----------------------------------------------------------------------+
16 // | Authors: Adam Daniel <adaniel1@eesus.jnj.com> |
17 // | Bertrand Mansion <bmansion@mamasam.com> |
18 // +----------------------------------------------------------------------+
20 // $Id$
22 require_once("HTML/QuickForm/element.php");
24 /**
25 * Base class for input form elements
27 * @author Adam Daniel <adaniel1@eesus.jnj.com>
28 * @author Bertrand Mansion <bmansion@mamasam.com>
29 * @version 1.0
30 * @since PHP4.04pl1
31 * @access public
32 * @abstract
34 class HTML_QuickForm_input extends HTML_QuickForm_element
36 // {{{ constructor
38 /**
39 * Class constructor
41 * @param string Input field name attribute
42 * @param mixed Label(s) for the input field
43 * @param mixed Either a typical HTML attribute string or an associative array
44 * @since 1.0
45 * @access public
46 * @return void
48 function HTML_QuickForm_input($elementName=null, $elementLabel=null, $attributes=null)
50 $this->HTML_QuickForm_element($elementName, $elementLabel, $attributes);
51 } //end constructor
53 // }}}
54 // {{{ setType()
56 /**
57 * Sets the element type
59 * @param string $type Element type
60 * @since 1.0
61 * @access public
62 * @return void
64 function setType($type)
66 $this->_type = $type;
67 $this->updateAttributes(array('type'=>$type));
68 } // end func setType
70 // }}}
71 // {{{ setName()
73 /**
74 * Sets the input field name
76 * @param string $name Input field name attribute
77 * @since 1.0
78 * @access public
79 * @return void
81 function setName($name)
83 $this->updateAttributes(array('name'=>$name));
84 } //end func setName
86 // }}}
87 // {{{ getName()
89 /**
90 * Returns the element name
92 * @since 1.0
93 * @access public
94 * @return string
96 function getName()
98 return $this->getAttribute('name');
99 } //end func getName
101 // }}}
102 // {{{ setValue()
105 * Sets the value of the form element
107 * @param string $value Default value of the form element
108 * @since 1.0
109 * @access public
110 * @return void
112 function setValue($value)
114 $this->updateAttributes(array('value'=>$value));
115 } // end func setValue
117 // }}}
118 // {{{ getValue()
121 * Returns the value of the form element
123 * @since 1.0
124 * @access public
125 * @return string
127 function getValue()
129 return $this->getAttribute('value');
130 } // end func getValue
132 // }}}
133 // {{{ toHtml()
136 * Returns the input field in HTML
138 * @since 1.0
139 * @access public
140 * @return string
142 function toHtml()
144 if ($this->_flagFrozen) {
145 return $this->getFrozenHtml();
146 } else {
147 return $this->_getTabs() . '<input' . $this->_getAttrString($this->_attributes) . ' />';
149 } //end func toHtml
151 // }}}
152 // {{{ onQuickFormEvent()
155 * Called by HTML_QuickForm whenever form event is made on this element
157 * @param string $event Name of event
158 * @param mixed $arg event arguments
159 * @param object $caller calling object
160 * @since 1.0
161 * @access public
162 * @return void
163 * @throws
165 function onQuickFormEvent($event, $arg, &$caller)
167 // do not use submit values for button-type elements
168 $type = $this->getType();
169 if (('updateValue' != $event) ||
170 ('submit' != $type && 'reset' != $type && 'image' != $type && 'button' != $type)) {
171 parent::onQuickFormEvent($event, $arg, $caller);
172 } else {
173 $value = $this->_findValue($caller->_constantValues);
174 if (null === $value) {
175 $value = $this->_findValue($caller->_defaultValues);
177 if (null !== $value) {
178 $this->setValue($value);
181 return true;
182 } // end func onQuickFormEvent
184 // }}}
185 // {{{ exportValue()
188 * We don't need values from button-type elements (except submit) and files
190 function exportValue(&$submitValues, $assoc = false)
192 $type = $this->getType();
193 if ('reset' == $type || 'image' == $type || 'button' == $type || 'file' == $type) {
194 return null;
195 } else {
196 return parent::exportValue($submitValues, $assoc);
200 // }}}
201 } // end class HTML_QuickForm_element