/[cvs]/nfo/php/libs/com.newsblob.phphtmllib/form/form_elements/FENumbers.inc
ViewVC logotype

Contents of /nfo/php/libs/com.newsblob.phphtmllib/form/form_elements/FENumbers.inc

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.3 - (show annotations)
Thu Aug 11 14:09:59 2005 UTC (18 years, 11 months ago) by jonen
Branch: MAIN
CVS Tags: HEAD
Changes since 1.2: +67 -20 lines
+ updated to version 2.5.3

1 <?php
2
3 /**
4 * This file contains the Form Element child classes
5 * that deal primarily with numbers.
6 *
7 * $Id: FENumbers.inc,v 1.6.2.1 2005/05/12 01:24:03 hemna Exp $
8 *
9 * @author Walter A. Boring IV <waboring@newsblob.com>
10 * @author Suren Markosyan <suren@bcsweb.com>
11 * @package phpHtmlLib
12 * @subpackage FormProcessing
13 *
14 * @copyright LGPL - See LICENCE
15 *
16 */
17
18 require_once($phphtmllib."/form/form_elements/FEText.inc");
19
20 /**
21 * This is the FormElement which builds a
22 * text input field that validates
23 * It validates as is_number().
24 *
25 *
26 * @author Walter A. Boring IV <waboring@newsblob.com>
27 * @author Suren Markossian <suren@bcsweb.com>
28 * @package phpHtmlLib
29 * @subpackage FormProcessing
30 *
31 * @copyright LGPL - See LICENCE
32 */
33 class FENumber extends FEText {
34
35 /**
36 * This method validates the data
37 * for this Form Element.
38 *
39 * It validates as is_float().
40 * @param FormValidation object.
41 */
42 function validate(&$_FormValidation) {
43 if (!$_FormValidation->is_number($this->get_value())) {
44 $this->set_error_message( $_FormValidation->get_error_message() );
45 return FALSE;
46 }
47 return TRUE;
48 }
49 }
50
51 /**
52 * This is the float FormElement which builds a
53 * text input field.
54 * It validates as is_float().
55 *
56 *
57 * @author Walter A. Boring IV <waboring@newsblob.com>
58 * @author Suren Markossian <suren@bcsweb.com>
59 * @package phpHtmlLib
60 * @subpackage FormProcessing
61 *
62 * @copyright LGPL - See LICENCE
63 */
64 class FENumberFloat extends FEText {
65
66 /**
67 * This method validates the data
68 * for this Form Element.
69 *
70 * It validates as is_float().
71 * @param FormValidation object.
72 */
73 function validate(&$_FormValidation) {
74 if (!$_FormValidation->is_float($this->get_value())) {
75 $this->set_error_message( $_FormValidation->get_error_message() );
76 return FALSE;
77 }
78 return TRUE;
79 }
80 }
81
82 /**
83 * This is the Price FormElement which builds a
84 * text input field.
85 * It validates as is_price().
86 *
87 *
88 * @author Walter A. Boring IV <waboring@newsblob.com>
89 * @author Suren Markossian <suren@bcsweb.com>
90 * @package phpHtmlLib
91 * @subpackage FormProcessing
92 *
93 * @copyright LGPL - See LICENCE
94 */
95 class FENumberPrice extends FEText {
96
97 /**
98 * This method validates the data
99 * for this Form Element.
100 *
101 * It validates as is_price().
102 * @param FormValidation object.
103 */
104 function validate(&$_FormValidation) {
105 if (!$_FormValidation->is_price($this->get_value())) {
106 $this->set_error_message( $_FormValidation->get_error_message() );
107 return FALSE;
108 }
109 return TRUE;
110 }
111 }
112
113 /**
114 * This is the Number Range FormElement which builds a
115 * text input field.
116 * It validates as is_within_rage().
117 *
118 *
119 * @author Walter A. Boring IV <waboring@newsblob.com>
120 * @author Suren Markossian <suren@bcsweb.com>
121 * @package phpHtmlLib
122 * @subpackage FormProcessing
123 *
124 * @copyright LGPL - See LICENCE
125 */
126 class FENumberInRange extends FEText {
127
128 /**
129 * The minimum #
130 */
131 var $_min = 0;
132 /**
133 * The maximum #
134 */
135 var $_max = 100;
136
137 /**
138 * Add the range to the label automatically?
139 */
140 var $_label_flag = TRUE;
141
142 /**
143 * The 'Range' text
144 */
145 var $_range_text = "Range";
146
147 /**
148 * The constructor
149 *
150 * @param label string - text label for the element
151 * @param bool required - is this a required element
152 * @param int required - element width in characters, pixels (px), percentage (%) or elements (em)
153 * @param int maximum number of chars allowed to type in the field
154 * @param int the minimum value allowable
155 * @param int the maximum value allowable
156 * @param boolean - add the range to the label automatically?
157 *
158 */
159 function FENumberInRange($label, $required = TRUE, $width = NULL,
160 $maxlength = NULL, $min=0, $max=100, $label_flag=TRUE) {
161 $this->FEText($label, $required, $width, $maxlength);
162 $this->_min = $min;
163 $this->_max = $max;
164 $this->_label_flag = $label_flag;
165 }
166
167 /**
168 * This function builds and returns a
169 * label object based on the label text
170 * and error conditions
171 *
172 * @param FormContent object that holds the
173 * required field marker
174 * @param string this string allows us to use this
175 * method and wrap any string as a FormElement
176 * label.
177 * @return object SPANtag
178 */
179 function get_label($form_content=NULL, $label='', $indent_flag=TRUE) {
180
181 $label = $this->get_label_text();
182
183 if ($this->_label_flag) {
184 $label .= " ".$this->get_range_string();
185 }
186
187 if ($this->_label_colon_flag) {
188 $label .= ':';
189 }
190
191 if ($this->is_required()) {
192 $text = ($form_content ? $form_content->_required_field_marker :
193 $this->get_required_symbol()). ' '.$label;
194 } else {
195 if ($indent_flag) {
196 $text = '&nbsp;&nbsp;'.$label;
197 } else {
198 $text = $label;
199 }
200 }
201
202 $span = html_span("formlabel", $text);
203
204 if ($this->has_error()) {
205 $span->set_tag_attribute("style","color:red;");
206 }
207
208 return $span;
209 }
210
211
212
213 /**
214 * This function builds a string for the range display
215 *
216 * @return string
217 */
218 function get_range_string($include_range=TRUE) {
219 if ($include_range) {
220 $str = $this->_range_text.": ";
221 } else {
222 $str = '';
223 }
224
225 return "(".$str.$this->_min."-".$this->_max.")";
226 }
227
228 /**
229 * This method validates the data
230 * for this Form Element.
231 *
232 * It validates as is_price().
233 * @param FormValidation object.
234 */
235 function validate(&$_FormValidation) {
236 if (!$_FormValidation->is_range($this->get_value(), NULL, $this->_min, $this->_max)) {
237 $this->set_error_message( $_FormValidation->get_error_message() );
238 return FALSE;
239 }
240 return TRUE;
241 }
242 }
243
244 ?>

MailToCvsAdmin">MailToCvsAdmin
ViewVC Help
Powered by ViewVC 1.1.26 RSS 2.0 feed