1 |
<?php |
2 |
/** |
3 |
* This file contains the base FEDataList class |
4 |
* |
5 |
* $Id: FEDataList.inc,v 1.6 2003/02/18 23:02:00 hemna Exp $ |
6 |
* |
7 |
* @author Walter A. Boring IV <waboring@buildabetterweb.com> |
8 |
* @author Suren Markosyan <suren@bcsweb.com> |
9 |
* @package phpHtmlLib |
10 |
* @subpackage FormProcessing |
11 |
* |
12 |
* @copyright LGPL - See LICENCE |
13 |
* |
14 |
*/ |
15 |
|
16 |
/** |
17 |
* This is the DataList FormElement which builds a |
18 |
* a complex FEBoxElement. It has no validation method. |
19 |
* |
20 |
* |
21 |
* @author Walter A. Boring IV <waboring@buildabetterweb.com> |
22 |
* @author Suren Markossian <suren@bcsweb.com> |
23 |
* @package phpHtmlLib |
24 |
* @subpackage FormProcessing |
25 |
* |
26 |
* @copyright LGPL - See LICENCE |
27 |
*/ |
28 |
class FEDataList extends FEBoxElement { |
29 |
|
30 |
/** |
31 |
* Holds the list of available |
32 |
* data elements |
33 |
* |
34 |
*/ |
35 |
var $_data_list = array(); |
36 |
|
37 |
/** |
38 |
* The constructor |
39 |
* |
40 |
* @param label string - text label for the element |
41 |
* @param bool required - is this a required element |
42 |
* @param array data_list - list of data elements (name=>value) |
43 |
* @param int required - element width in characters, pixels (px), percentage (%) or elements (em) |
44 |
*/ |
45 |
function FEDataList($label, $required = TRUE, $width = NULL, $height = NULL, $data_list = array()) { |
46 |
$this->FEBoxElement($label, $required, $width, $height); |
47 |
$this->_data_list = $data_list; |
48 |
} |
49 |
|
50 |
|
51 |
/** |
52 |
* This provides a method |
53 |
* for the FormContent |
54 |
* to get access to the |
55 |
* text associated with a |
56 |
* field. This is only available |
57 |
* on FormElements that have text |
58 |
* associated with a field. |
59 |
* It is used during Confirmation |
60 |
* |
61 |
* @param mixed - the value to look up |
62 |
* @return string - the text associated |
63 |
*/ |
64 |
function get_value_text($value) { |
65 |
$flip = array_flip($this->_data_list); |
66 |
return $flip[$value]; |
67 |
} |
68 |
|
69 |
/** |
70 |
* |
71 |
* This function is responsible for performing complete |
72 |
* validation and setting the appropriate error message |
73 |
* in case of a failed validation |
74 |
* |
75 |
*/ |
76 |
function validate() { |
77 |
// we make sure that the value is in the data list |
78 |
$values = $this->get_value(); |
79 |
if (is_array($values) ) { |
80 |
foreach( $values as $value ) { |
81 |
if (!in_array($value, $this->_data_list)) { |
82 |
$this->set_error_message("Invalid value"); |
83 |
return FALSE; |
84 |
} |
85 |
} |
86 |
} else { |
87 |
if (!in_array($values, $this->_data_list)) { |
88 |
$this->set_error_message("Invalid value"); |
89 |
return FALSE; |
90 |
} |
91 |
} |
92 |
|
93 |
|
94 |
return TRUE; |
95 |
} |
96 |
} |
97 |
?> |