1 |
jonen |
1.1 |
<?php |
2 |
|
|
/** |
3 |
|
|
* This file contains the FEText, FEName, FEEmail, |
4 |
|
|
* FEDomainName classes |
5 |
|
|
* |
6 |
jonen |
1.3 |
* $Id: FEText.inc,v 1.20 2004/03/08 15:37:53 culley Exp $ |
7 |
jonen |
1.1 |
* |
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 |
jonen |
1.3 |
function FEText($label, $required = FALSE, $width = NULL, $maxlength = NULL) { |
40 |
jonen |
1.1 |
$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 |
jonen |
1.2 |
return new INPUTtag($attributes); |
69 |
jonen |
1.1 |
} |
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 |
jonen |
1.2 |
* @param FormValidation object. |
92 |
jonen |
1.1 |
*/ |
93 |
jonen |
1.2 |
function validate(&$_FormValidation) { |
94 |
|
|
if (!$_FormValidation->is_name($this->get_value())) { |
95 |
|
|
$this->set_error_message( $_FormValidation->get_error_message() ); |
96 |
jonen |
1.1 |
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 |
jonen |
1.2 |
* @param FormValidation object. |
123 |
jonen |
1.1 |
*/ |
124 |
jonen |
1.2 |
function validate($_FormValidation) { |
125 |
|
|
if (!$_FormValidation->is_email($this->get_value())) { |
126 |
|
|
$this->set_error_message( $_FormValidation->get_error_message() ); |
127 |
jonen |
1.1 |
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 |
jonen |
1.2 |
* @param FormValidation object. |
156 |
jonen |
1.1 |
*/ |
157 |
jonen |
1.2 |
function validate(&$_FormValidation) { |
158 |
|
|
if (!$_FormValidation->is_manyemails($this->get_value())) { |
159 |
|
|
$this->set_error_message( $_FormValidation->get_error_message() ); |
160 |
jonen |
1.1 |
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 |
jonen |
1.2 |
* @param FormValidation object. |
187 |
jonen |
1.1 |
*/ |
188 |
jonen |
1.2 |
function validate(&$_FormValidation) { |
189 |
|
|
if (!$_FormValidation->is_domainname($this->get_value())) { |
190 |
|
|
$this->set_error_message( $_FormValidation->get_error_message() ); |
191 |
jonen |
1.1 |
return FALSE; |
192 |
|
|
} |
193 |
|
|
return TRUE; |
194 |
|
|
} |
195 |
|
|
} |
196 |
|
|
|
197 |
|
|
/** |
198 |
jonen |
1.2 |
* This is the DomainName FormElement which builds a |
199 |
|
|
* text input field. It also includes a port # |
200 |
|
|
* It validates as is_domainname(). |
201 |
jonen |
1.1 |
* |
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 |
jonen |
1.2 |
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 |
jonen |
1.1 |
|
279 |
|
|
/** |
280 |
|
|
* This method validates the data |
281 |
|
|
* for this Form Element. |
282 |
|
|
* |
283 |
jonen |
1.2 |
* It validates as is_domainname(). |
284 |
|
|
* @param FormValidation object. |
285 |
jonen |
1.1 |
*/ |
286 |
jonen |
1.2 |
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 |
jonen |
1.1 |
} |
329 |
jonen |
1.2 |
|
330 |
|
|
return $valid; |
331 |
jonen |
1.1 |
} |
332 |
|
|
} |
333 |
|
|
|
334 |
|
|
/** |
335 |
jonen |
1.2 |
* This is the Ip Address FormElement which builds a |
336 |
jonen |
1.1 |
* text input field. |
337 |
jonen |
1.2 |
* It validates as is_ip(). |
338 |
jonen |
1.1 |
* |
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 |
jonen |
1.2 |
class FEIPAddress extends FEText { |
348 |
jonen |
1.1 |
|
349 |
|
|
/** |
350 |
|
|
* This method validates the data |
351 |
|
|
* for this Form Element. |
352 |
|
|
* |
353 |
jonen |
1.2 |
* It validates as is_ip(). |
354 |
|
|
* @param FormValidation object. |
355 |
jonen |
1.1 |
*/ |
356 |
jonen |
1.2 |
function validate(&$_FormValidation) { |
357 |
|
|
if (!$_FormValidation->is_ip($this->get_value())) { |
358 |
|
|
$this->set_error_message( $_FormValidation->get_error_message() ); |
359 |
jonen |
1.1 |
return FALSE; |
360 |
|
|
} |
361 |
|
|
return TRUE; |
362 |
|
|
} |
363 |
|
|
} |
364 |
|
|
|
365 |
|
|
/** |
366 |
jonen |
1.2 |
* This is the Ip Address FormElement which builds a |
367 |
jonen |
1.1 |
* text input field. |
368 |
jonen |
1.2 |
* It validates as is_ip(). |
369 |
jonen |
1.1 |
* |
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 |
jonen |
1.2 |
class FEIPAddressWithPort extends FEHostNameWithPort { |
379 |
jonen |
1.1 |
|
380 |
|
|
/** |
381 |
jonen |
1.2 |
* 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 |
jonen |
1.1 |
} |
392 |
jonen |
1.2 |
return $valid; |
393 |
jonen |
1.1 |
} |
394 |
|
|
} |
395 |
|
|
|
396 |
jonen |
1.2 |
|
397 |
|
|
|
398 |
jonen |
1.1 |
/** |
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 |
jonen |
1.2 |
* @param FormValidation object. |
419 |
jonen |
1.1 |
*/ |
420 |
jonen |
1.2 |
function validate(&$_FormValidation) { |
421 |
|
|
if (!$_FormValidation->is_url($this->get_value())) { |
422 |
|
|
$this->set_error_message( $_FormValidation->get_error_message() ); |
423 |
jonen |
1.1 |
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 |
jonen |
1.2 |
* @param FormValidation object. |
451 |
jonen |
1.1 |
*/ |
452 |
jonen |
1.2 |
function validate(&$_FormValidation) { |
453 |
|
|
if (!$_FormValidation->is_strict_url($this->get_value())) { |
454 |
|
|
$this->set_error_message( $_FormValidation->get_error_message() ); |
455 |
jonen |
1.3 |
return FALSE; |
456 |
|
|
} |
457 |
|
|
return TRUE; |
458 |
|
|
} |
459 |
|
|
} |
460 |
|
|
|
461 |
|
|
/** |
462 |
|
|
* This is the FEZipcode class. |
463 |
|
|
* |
464 |
|
|
* @author Walter A. Boring IV <waboring@buildabetterweb.com> |
465 |
|
|
*/ |
466 |
|
|
class FEZipcode extends FEText { |
467 |
|
|
/** |
468 |
|
|
* The constructor |
469 |
|
|
* |
470 |
|
|
* @param label string - text label for the element |
471 |
|
|
* @param bool required - is this a required element |
472 |
|
|
* @param int required - element width in characters, pixels (px), percentage (%) or elements (em) |
473 |
|
|
* @param int required - maximum number of chars allowed to type in |
474 |
|
|
*/ |
475 |
|
|
function FEZipcode($label, $required=false, $width = NULL, $maxlength = 5) { |
476 |
|
|
$this->FEText($label, $required, $width, $maxlength); |
477 |
|
|
} |
478 |
|
|
|
479 |
|
|
|
480 |
|
|
/** |
481 |
|
|
* This method validates the data |
482 |
|
|
* for this Form Element. |
483 |
|
|
* |
484 |
|
|
* It validates as is_name(). |
485 |
|
|
* @param FormValidation object. |
486 |
|
|
*/ |
487 |
|
|
function validate(&$_FormValidation) { |
488 |
|
|
if (!$_FormValidation->is_zip($this->get_value())) { |
489 |
|
|
$this->set_error_message( $_FormValidation->get_error_message() ); |
490 |
|
|
return FALSE; |
491 |
|
|
} |
492 |
|
|
return TRUE; |
493 |
|
|
} |
494 |
|
|
} |
495 |
|
|
|
496 |
|
|
/** |
497 |
|
|
* This is the RegEx FormElement which builds a |
498 |
|
|
* text input field, and validates against the |
499 |
|
|
* is_regex() method. |
500 |
|
|
* |
501 |
|
|
* @author Culley Harrelson <culley@fastmail.fm> |
502 |
|
|
* @package phpHtmlLib |
503 |
|
|
* @subpackage FormProcessing |
504 |
|
|
* |
505 |
|
|
* @copyright LGPL - See LICENCE |
506 |
|
|
*/ |
507 |
|
|
class FERegEx extends FEText { |
508 |
|
|
|
509 |
|
|
var $_regex; |
510 |
|
|
var $_error_message; |
511 |
|
|
|
512 |
|
|
/** |
513 |
|
|
* The constructor |
514 |
|
|
* |
515 |
|
|
* @param label string - text label for the element |
516 |
|
|
* @param required bool- is this a required element |
517 |
|
|
* @param width int - element width in characters, pixels (px), percentage (%) or elements (em) |
518 |
|
|
* @param maxlength int- maximum number of chars allowed to type in |
519 |
|
|
* @param regex string - a valid regular expression i.e. '/[a-z]+$/i' |
520 |
|
|
* @param error_message string - error message for failure to match the regex |
521 |
|
|
*/ |
522 |
|
|
function FERegEx($label, $required=false, $width = NULL, $maxlength = NULL, $regex, $error_message) { |
523 |
|
|
$this->FEText($label, $required, $width, $maxlength); |
524 |
|
|
$this->_regex = $regex; |
525 |
|
|
$this->_error_message = $error_message; |
526 |
|
|
} |
527 |
|
|
|
528 |
|
|
/** |
529 |
|
|
* This method validates the data |
530 |
|
|
* for this Form Element. |
531 |
|
|
* |
532 |
|
|
* It validates as is_regex(). |
533 |
|
|
* @param FormValidation object. |
534 |
|
|
*/ |
535 |
|
|
function validate(&$_FormValidation) { |
536 |
|
|
if (!$_FormValidation->is_regex($this->_regex, $this->get_value())) { |
537 |
|
|
$this->set_error_message( $this->_error_message ); |
538 |
jonen |
1.1 |
return FALSE; |
539 |
|
|
} |
540 |
|
|
return TRUE; |
541 |
|
|
} |
542 |
|
|
} |
543 |
|
|
?> |