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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (show annotations)
Sat Sep 20 00:20:15 2003 UTC (21 years ago) by jonen
Branch: MAIN
Changes since 1.1: +33 -1 lines
+ updated whole phphtmllib to v2.3.0

1 <?php
2 /**
3 * This file contains the FEListBox, FEMultiListBox
4 *
5 * $Id: FEListBox.inc,v 1.5 2003/07/17 02:05:20 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 ListBox FormElement which builds a
18 * select field with all of its options.
19 * 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 FEListBox extends FEDataList {
30
31 /**
32 * This function builds and returns the
33 * form element object
34 *
35 * @return object
36 */
37 function get_element() {
38
39 $attributes = $this->_build_element_attributes();
40
41 if ($this->_height) {
42 $attributes["size"] = 5;
43 }
44
45 $selected_value = $this->get_value();
46
47 $tag = new SELECTtag($attributes);
48
49 foreach ($this->_data_list as $name=>$value) {
50
51 $attributes = array("value"=>$value);
52 if ($value == $selected_value) $attributes[] = "selected";
53
54 $tag->add(new OPTIONtag($attributes, $name));
55 }
56 return $tag;
57 }
58 }
59
60 /**
61 * Build a Yes/No Select box
62 *
63 * @author Walter A. Boring IV <waboring@buildabetterweb.com>
64 * @author Suren Markossian <suren@bcsweb.com>
65 * @package phpHtmlLib
66 * @subpackage FormProcessing
67 *
68 * @copyright LGPL - See LICENCE
69 */
70 class FEYesNoListBox extends FEListBox {
71
72 /**
73 * The Constructor
74 *
75 * @param label string - text label for the element
76 * @param bool required - is this a required element
77 * @param array data_list - list of data elements (name=>value)
78 * @param int required - element width in characters, pixels (px), percentage (%) or elements (em)
79 * @param string - the value to use for the 'yes' radio
80 * NOTE: default is 'yes'
81 * @param string - the value to use for the 'no' radio
82 * NOTE: default is 'no'
83 */
84 function FEYesNoListBox($label, $required = TRUE, $width = NULL, $height = NULL,
85 $yes_value="yes", $no_value="no") {
86 $options = array("Yes" => $yes_value, "No" => $no_value);
87 $this->FEListBox($label, $required, $width, $height, $options);
88 }
89 }
90
91
92 /**
93 * This is the MultiListBox FormElement which builds a
94 * select field with all of its options. It enables
95 * the ability to have multiple selections.
96 * It has no validation method.
97 *
98 *
99 * @author Walter A. Boring IV <waboring@buildabetterweb.com>
100 * @author Suren Markossian <suren@bcsweb.com>
101 * @package phpHtmlLib
102 * @subpackage FormProcessing
103 *
104 * @copyright LGPL - See LICENCE
105 */
106 class FEMultiListBox extends FEListBox {
107
108
109 /**
110 * This function creates element name
111 * used in the form based on the text label
112 * or any other parameters
113 *
114 * Overriding things function to make sure
115 * an array is created instead of a single variable
116 */
117 function create_element_name() {
118
119 parent::create_element_name();
120
121 $this->_element_name .= "[]";
122 }
123
124 /**
125 * This function builds and returns the
126 * form element object
127 *
128 * @return object
129 */
130 function get_element() {
131
132 $attributes = $this->_build_element_attributes();
133
134 $attributes[] = "multiple";
135
136 if ($this->_height) {
137 $attributes["size"] = 5;
138 }
139
140 $selected_values = $this->get_value();
141
142 $tag = new SELECTtag($attributes);
143
144 foreach ($this->_data_list as $name=>$value) {
145
146 $attributes = array("value"=>$value);
147 if (is_array($selected_values) && in_array($value, $selected_values)) $attributes[] = "selected";
148
149 $tag->add(new OPTIONtag($attributes, $name));
150 }
151 return $tag;
152 }
153 }
154 ?>

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