1 |
jonen |
1.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.2 2003/07/18 01:23:43 hemna Exp $ |
8 |
|
|
* |
9 |
|
|
* @author Walter A. Boring IV <waboring@buildabetterweb.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@buildabetterweb.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@buildabetterweb.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@buildabetterweb.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@buildabetterweb.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 constructor |
144 |
|
|
* |
145 |
|
|
* @param label string - text label for the element |
146 |
|
|
* @param bool required - is this a required element |
147 |
|
|
* @param int required - element width in characters, pixels (px), percentage (%) or elements (em) |
148 |
|
|
* @param int maximum number of chars allowed to type in the field |
149 |
|
|
* @param int the minimum value allowable |
150 |
|
|
* @param int the maximum value allowable |
151 |
|
|
* @param boolean - add the range to the label automatically? |
152 |
|
|
* |
153 |
|
|
*/ |
154 |
|
|
function FENumberInRange($label, $required = TRUE, $width = NULL, |
155 |
|
|
$maxlength = NULL, $min=0, $max=100, $label_flag=TRUE) { |
156 |
|
|
$this->FEText($label, $required, $width, $maxlength); |
157 |
|
|
$this->_min = $min; |
158 |
|
|
$this->_max = $max; |
159 |
|
|
$this->_label_flag = $label_flag; |
160 |
|
|
} |
161 |
|
|
|
162 |
|
|
function get_label() { |
163 |
|
|
|
164 |
|
|
$label = $this->get_label_text(); |
165 |
|
|
|
166 |
|
|
if ($this->_label_flag) { |
167 |
|
|
$label .= " (".$this->_min."-".$this->_max.")"; |
168 |
|
|
} |
169 |
|
|
|
170 |
|
|
if ($this->is_required()) $label .= ' ' . $this->get_required_symbol(); |
171 |
|
|
|
172 |
|
|
$span = html_span("formlabel", $label); |
173 |
|
|
|
174 |
|
|
if ($this->has_error()) { |
175 |
|
|
$span->set_tag_attribute("style","color:red;"); |
176 |
|
|
} |
177 |
|
|
|
178 |
|
|
return $span; |
179 |
|
|
} |
180 |
|
|
|
181 |
|
|
/** |
182 |
|
|
* This method validates the data |
183 |
|
|
* for this Form Element. |
184 |
|
|
* |
185 |
|
|
* It validates as is_price(). |
186 |
|
|
* @param FormValidation object. |
187 |
|
|
*/ |
188 |
|
|
function validate(&$_FormValidation) { |
189 |
|
|
if (!$_FormValidation->is_range($this->get_value(), NULL, $this->_min, $this->_max)) { |
190 |
|
|
$this->set_error_message( $_FormValidation->get_error_message() ); |
191 |
|
|
return FALSE; |
192 |
|
|
} |
193 |
|
|
return TRUE; |
194 |
|
|
} |
195 |
|
|
} |
196 |
|
|
|
197 |
|
|
?> |