1 |
<?php |
2 |
/** |
3 |
* This file contains the FEText, FEName, FEEmail, |
4 |
* FEDomainName classes |
5 |
* |
6 |
* $Id: FEText.inc,v 1.17 2003/07/18 01:23:43 hemna Exp $ |
7 |
* |
8 |
* @author Walter A. Boring IV <waboring@buildabetterweb.com> |
9 |
* @author Suren Markosyan <suren@bcsweb.com> |
10 |
* @package phpHtmlLib |
11 |
* @subpackage FormProcessing |
12 |
* |
13 |
* @copyright LGPL - See LICENCE |
14 |
* |
15 |
*/ |
16 |
|
17 |
/** |
18 |
* This is the Text FormElement which builds a |
19 |
* text input field. It has no validation method. |
20 |
* |
21 |
* |
22 |
* @author Walter A. Boring IV <waboring@buildabetterweb.com> |
23 |
* @author Suren Markossian <suren@bcsweb.com> |
24 |
* @package phpHtmlLib |
25 |
* @subpackage FormProcessing |
26 |
* |
27 |
* @copyright LGPL - See LICENCE |
28 |
*/ |
29 |
class FEText extends FormElement { |
30 |
|
31 |
/** |
32 |
* The constructor |
33 |
* |
34 |
* @param label string - text label for the element |
35 |
* @param bool required - is this a required element |
36 |
* @param int required - element width in characters, pixels (px), percentage (%) or elements (em) |
37 |
* @param int required - maximum number of chars allowed to type in |
38 |
*/ |
39 |
function FEText($label, $required = TRUE, $width = NULL, $maxlength = NULL) { |
40 |
$this->FormElement($label, $required); |
41 |
|
42 |
if ($width != NULL) { |
43 |
if (is_numeric($width)) |
44 |
$this->set_attribute("size", $width); |
45 |
else |
46 |
$this->set_style_attribute("width", $width); |
47 |
} |
48 |
|
49 |
if ($maxlength != NULL) |
50 |
$this->set_attribute("maxlength", $maxlength); |
51 |
} |
52 |
|
53 |
|
54 |
/** |
55 |
* This function builds and returns the |
56 |
* form element object |
57 |
* |
58 |
* @return object |
59 |
*/ |
60 |
function get_element() { |
61 |
|
62 |
$attributes = $this->_build_element_attributes(); |
63 |
$attributes["type"] = "text"; |
64 |
|
65 |
if (($value = $this->get_value()) != NULL) |
66 |
$attributes["value"] = $value; |
67 |
|
68 |
return new INPUTtag($attributes); |
69 |
} |
70 |
} |
71 |
|
72 |
/** |
73 |
* This is the Name FormElement which builds a |
74 |
* text input field, and validates against the |
75 |
* is_name() method. |
76 |
* |
77 |
* @author Walter A. Boring IV <waboring@buildabetterweb.com> |
78 |
* @author Suren Markossian <suren@bcsweb.com> |
79 |
* @package phpHtmlLib |
80 |
* @subpackage FormProcessing |
81 |
* |
82 |
* @copyright LGPL - See LICENCE |
83 |
*/ |
84 |
class FEName extends FEText { |
85 |
|
86 |
/** |
87 |
* This method validates the data |
88 |
* for this Form Element. |
89 |
* |
90 |
* It validates as is_name(). |
91 |
* @param FormValidation object. |
92 |
*/ |
93 |
function validate(&$_FormValidation) { |
94 |
if (!$_FormValidation->is_name($this->get_value())) { |
95 |
$this->set_error_message( $_FormValidation->get_error_message() ); |
96 |
return FALSE; |
97 |
} |
98 |
return TRUE; |
99 |
} |
100 |
} |
101 |
|
102 |
/** |
103 |
* This is the Email FormElement which builds a |
104 |
* text input field. |
105 |
* It validatest he data as is_email() |
106 |
* |
107 |
* |
108 |
* @author Walter A. Boring IV <waboring@buildabetterweb.com> |
109 |
* @author Suren Markossian <suren@bcsweb.com> |
110 |
* @package phpHtmlLib |
111 |
* @subpackage FormProcessing |
112 |
* |
113 |
* @copyright LGPL - See LICENCE |
114 |
*/ |
115 |
class FEEmail extends FEText { |
116 |
|
117 |
/** |
118 |
* This method validates the data |
119 |
* for this Form Element. |
120 |
* |
121 |
* It validates as is_email(). |
122 |
* @param FormValidation object. |
123 |
*/ |
124 |
function validate($_FormValidation) { |
125 |
if (!$_FormValidation->is_email($this->get_value())) { |
126 |
$this->set_error_message( $_FormValidation->get_error_message() ); |
127 |
return FALSE; |
128 |
} |
129 |
return TRUE; |
130 |
} |
131 |
} |
132 |
|
133 |
/** |
134 |
* This is the EmailMany FormElement which builds a |
135 |
* text input field. This allows for multiple email |
136 |
* addresses in 1 text input field seperated by commas. |
137 |
* |
138 |
* It validatest he data as is_manyemails() |
139 |
* |
140 |
* |
141 |
* @author Walter A. Boring IV <waboring@buildabetterweb.com> |
142 |
* @author Suren Markossian <suren@bcsweb.com> |
143 |
* @package phpHtmlLib |
144 |
* @subpackage FormProcessing |
145 |
* |
146 |
* @copyright LGPL - See LICENCE |
147 |
*/ |
148 |
class FEEmailMany extends FEText { |
149 |
|
150 |
/** |
151 |
* This method validates the data |
152 |
* for this Form Element. |
153 |
* |
154 |
* It validates as is_manyemails(). |
155 |
* @param FormValidation object. |
156 |
*/ |
157 |
function validate(&$_FormValidation) { |
158 |
if (!$_FormValidation->is_manyemails($this->get_value())) { |
159 |
$this->set_error_message( $_FormValidation->get_error_message() ); |
160 |
return FALSE; |
161 |
} |
162 |
return TRUE; |
163 |
} |
164 |
} |
165 |
|
166 |
/** |
167 |
* This is the DomainName FormElement which builds a |
168 |
* text input field. |
169 |
* It validates as is_domainname(). |
170 |
* |
171 |
* |
172 |
* @author Walter A. Boring IV <waboring@buildabetterweb.com> |
173 |
* @author Suren Markossian <suren@bcsweb.com> |
174 |
* @package phpHtmlLib |
175 |
* @subpackage FormProcessing |
176 |
* |
177 |
* @copyright LGPL - See LICENCE |
178 |
*/ |
179 |
class FEDomainName extends FEText { |
180 |
|
181 |
/** |
182 |
* This method validates the data |
183 |
* for this Form Element. |
184 |
* |
185 |
* It validates as is_domainname(). |
186 |
* @param FormValidation object. |
187 |
*/ |
188 |
function validate(&$_FormValidation) { |
189 |
if (!$_FormValidation->is_domainname($this->get_value())) { |
190 |
$this->set_error_message( $_FormValidation->get_error_message() ); |
191 |
return FALSE; |
192 |
} |
193 |
return TRUE; |
194 |
} |
195 |
} |
196 |
|
197 |
/** |
198 |
* This is the DomainName FormElement which builds a |
199 |
* text input field. It also includes a port # |
200 |
* It validates as is_domainname(). |
201 |
* |
202 |
* |
203 |
* @author Walter A. Boring IV <waboring@buildabetterweb.com> |
204 |
* @author Suren Markossian <suren@bcsweb.com> |
205 |
* @package phpHtmlLib |
206 |
* @subpackage FormProcessing |
207 |
* |
208 |
* @copyright LGPL - See LICENCE |
209 |
*/ |
210 |
class FEHostNameWithPort extends FEText { |
211 |
|
212 |
/** |
213 |
* flag to tell us to seperate the port |
214 |
* value into it's own field |
215 |
*/ |
216 |
var $_seperate_port_flag = FALSE; |
217 |
|
218 |
/** |
219 |
* The constructor |
220 |
* |
221 |
* @param label string - text label for the element |
222 |
* @param bool required - is this a required element |
223 |
* @param int required - element width in characters, pixels (px), percentage (%) or elements (em) |
224 |
* @param int required - maximum number of chars allowed to type in |
225 |
* @param bool optional - seperate the port value into it's own textarea field |
226 |
*/ |
227 |
function FEHostNameWithPort($label, $required = TRUE, $width = NULL, $maxlength = NULL, |
228 |
$seperate_port=FALSE) { |
229 |
$this->FEText($label, $required, $width, $maxlength); |
230 |
$this->_seperate_port_flag = $seperate_port; |
231 |
} |
232 |
|
233 |
/** |
234 |
* This function builds and returns the |
235 |
* form element object |
236 |
* |
237 |
* @return object |
238 |
*/ |
239 |
function get_element() { |
240 |
$host_attributes = $this->_build_element_attributes(); |
241 |
$host_attributes["type"] = "text"; |
242 |
|
243 |
$element_name = $this->get_element_name(); |
244 |
$host_value = $this->get_value(); |
245 |
|
246 |
if ($this->_seperate_port_flag) { |
247 |
$host_attributes["name"] = $element_name."[0]"; |
248 |
if ($host_value != NULL && !is_array($host_value)) { |
249 |
$host_value = explode(":", $host_value ); |
250 |
$host_attributes["value"] = $host_value[0]; |
251 |
} else if (is_array($host_value)) { |
252 |
$host_attributes["value"] = $host_value[0]; |
253 |
} |
254 |
|
255 |
$port_attributes = $host_attributes; |
256 |
$port_attributes["name"] = $element_name."[1]"; |
257 |
$port_attributes["size"] = 10; |
258 |
$port_attributes["maxlenght"] = 5; |
259 |
if (@array_key_exists("0", $host_value)) { |
260 |
$port_attributes["value"] = $host_value[1]; |
261 |
} |
262 |
|
263 |
$port_label = html_span("formlabel", "Port"); |
264 |
if ($this->has_error("Port")) { |
265 |
$port_label->set_tag_attribute("style","color:red;"); |
266 |
} |
267 |
|
268 |
return container( new INPUTtag($host_attributes), |
269 |
$port_label, |
270 |
new INPUTtag($port_attributes)); |
271 |
} else { |
272 |
if ($host_value != NULL) { |
273 |
$host_attributes["value"] = $host_value; |
274 |
} |
275 |
return new INPUTtag($host_attributes); |
276 |
} |
277 |
} |
278 |
|
279 |
/** |
280 |
* This method validates the data |
281 |
* for this Form Element. |
282 |
* |
283 |
* It validates as is_domainname(). |
284 |
* @param FormValidation object. |
285 |
*/ |
286 |
function validate(&$_FormValidation) { |
287 |
$value = $this->get_value(); |
288 |
if (!is_array($value)) { |
289 |
$value = explode(":", $value); |
290 |
} |
291 |
|
292 |
$valid = $this->_validate_hostname($_FormValidation, $value[0]); |
293 |
|
294 |
//now validate the port |
295 |
if ($value[1] != NULL) { |
296 |
if (!$_FormValidation->is_number($value[1])) { |
297 |
if ($this->_seperate_port_flag) { |
298 |
$this->set_error_message($_FormValidation->get_error_message(), "Port"); |
299 |
} else { |
300 |
$this->set_error_message( $_FormValidation->get_error_message() ); |
301 |
} |
302 |
$value = FALSE; |
303 |
} |
304 |
|
305 |
//make sure the hostname isn't null |
306 |
if ($value[0] == NULL) { |
307 |
//we have an error here because |
308 |
//they entered a port w/o a hostname |
309 |
$_FormValidation->_error("", "This field cannot be empty, if the Port is filled out"); |
310 |
$this->set_error_message($_FormValidation->get_error_message()); |
311 |
} |
312 |
} |
313 |
return $valid; |
314 |
} |
315 |
|
316 |
|
317 |
/** |
318 |
* this validates the hostname field only |
319 |
* |
320 |
* @return bool TRUE = valid |
321 |
*/ |
322 |
function _validate_hostname(&$_FormValidation, $value) { |
323 |
$valid = TRUE; |
324 |
//validate the hostname |
325 |
if ($value != NULL && !$_FormValidation->is_hostname($value)) { |
326 |
$this->set_error_message( $_FormValidation->get_error_message() ); |
327 |
$valid = FALSE; |
328 |
} |
329 |
|
330 |
return $valid; |
331 |
} |
332 |
} |
333 |
|
334 |
/** |
335 |
* This is the Ip Address FormElement which builds a |
336 |
* text input field. |
337 |
* It validates as is_ip(). |
338 |
* |
339 |
* |
340 |
* @author Walter A. Boring IV <waboring@buildabetterweb.com> |
341 |
* @author Suren Markossian <suren@bcsweb.com> |
342 |
* @package phpHtmlLib |
343 |
* @subpackage FormProcessing |
344 |
* |
345 |
* @copyright LGPL - See LICENCE |
346 |
*/ |
347 |
class FEIPAddress extends FEText { |
348 |
|
349 |
/** |
350 |
* This method validates the data |
351 |
* for this Form Element. |
352 |
* |
353 |
* It validates as is_ip(). |
354 |
* @param FormValidation object. |
355 |
*/ |
356 |
function validate(&$_FormValidation) { |
357 |
if (!$_FormValidation->is_ip($this->get_value())) { |
358 |
$this->set_error_message( $_FormValidation->get_error_message() ); |
359 |
return FALSE; |
360 |
} |
361 |
return TRUE; |
362 |
} |
363 |
} |
364 |
|
365 |
/** |
366 |
* This is the Ip Address FormElement which builds a |
367 |
* text input field. |
368 |
* It validates as is_ip(). |
369 |
* |
370 |
* |
371 |
* @author Walter A. Boring IV <waboring@buildabetterweb.com> |
372 |
* @author Suren Markossian <suren@bcsweb.com> |
373 |
* @package phpHtmlLib |
374 |
* @subpackage FormProcessing |
375 |
* |
376 |
* @copyright LGPL - See LICENCE |
377 |
*/ |
378 |
class FEIPAddressWithPort extends FEHostNameWithPort { |
379 |
|
380 |
/** |
381 |
* this validates the hostname field only |
382 |
* |
383 |
* @return bool TRUE = valid |
384 |
*/ |
385 |
function _validate_hostname(&$_FormValidation, $value) { |
386 |
$valid = TRUE; |
387 |
//validate the hostname |
388 |
if ($value != NULL && !$_FormValidation->is_ip($value)) { |
389 |
$this->set_error_message( $_FormValidation->get_error_message() ); |
390 |
$valid = FALSE; |
391 |
} |
392 |
return $valid; |
393 |
} |
394 |
} |
395 |
|
396 |
|
397 |
|
398 |
/** |
399 |
* This is the URL FormElement which builds a |
400 |
* text input field. |
401 |
* It validates as is_url(). |
402 |
* |
403 |
* |
404 |
* @author Walter A. Boring IV <waboring@buildabetterweb.com> |
405 |
* @author Suren Markossian <suren@bcsweb.com> |
406 |
* @package phpHtmlLib |
407 |
* @subpackage FormProcessing |
408 |
* |
409 |
* @copyright LGPL - See LICENCE |
410 |
*/ |
411 |
class FEUrl extends FEText { |
412 |
|
413 |
/** |
414 |
* This method validates the data |
415 |
* for this Form Element. |
416 |
* |
417 |
* It validates as is_url(). |
418 |
* @param FormValidation object. |
419 |
*/ |
420 |
function validate(&$_FormValidation) { |
421 |
if (!$_FormValidation->is_url($this->get_value())) { |
422 |
$this->set_error_message( $_FormValidation->get_error_message() ); |
423 |
return FALSE; |
424 |
} |
425 |
return TRUE; |
426 |
} |
427 |
} |
428 |
|
429 |
/** |
430 |
* This is the URLStrict FormElement which builds a |
431 |
* text input field. |
432 |
* This is the same as FEUrl, but it requires the http:// |
433 |
* It validates as is_strict_url(). |
434 |
* |
435 |
* |
436 |
* @author Walter A. Boring IV <waboring@buildabetterweb.com> |
437 |
* @author Suren Markossian <suren@bcsweb.com> |
438 |
* @package phpHtmlLib |
439 |
* @subpackage FormProcessing |
440 |
* |
441 |
* @copyright LGPL - See LICENCE |
442 |
*/ |
443 |
class FEUrlStrict extends FEText { |
444 |
|
445 |
/** |
446 |
* This method validates the data |
447 |
* for this Form Element. |
448 |
* |
449 |
* It validates as is_strict_url(). |
450 |
* @param FormValidation object. |
451 |
*/ |
452 |
function validate(&$_FormValidation) { |
453 |
if (!$_FormValidation->is_strict_url($this->get_value())) { |
454 |
$this->set_error_message( $_FormValidation->get_error_message() ); |
455 |
return FALSE; |
456 |
} |
457 |
return TRUE; |
458 |
} |
459 |
} |
460 |
?> |