1 |
<?php |
2 |
/** |
3 |
* This file holds the babw Standard Form Content |
4 |
* which is a child of the FormContent object. |
5 |
* This provides a "standard" look for the outer |
6 |
* wrapper for all forms. |
7 |
* All forms have a Save and Cancel button, as well |
8 |
* as a Confirmation of the Form. |
9 |
* |
10 |
* |
11 |
* $Id: StandardFormContent.inc,v 1.9 2003/04/17 06:03:29 hemna Exp $ |
12 |
* |
13 |
* @author Walter A. Boring IV <waboring@buildabetterweb.com> |
14 |
* @package phpHtmlLib |
15 |
* @subpackage FormProcessing |
16 |
*/ |
17 |
|
18 |
/** |
19 |
* This is a child of the FormContent class to |
20 |
* provide a 'standard' look and feel for forms. |
21 |
* It also enables a confirmation 'page' by default. |
22 |
* |
23 |
* @package phpHtmlLib |
24 |
* @subpackage FormProcessing |
25 |
*/ |
26 |
class StandardFormContent extends FormContent { |
27 |
|
28 |
|
29 |
/** |
30 |
* The title used in the wrapping table |
31 |
* |
32 |
*/ |
33 |
var $_form_title = ""; |
34 |
|
35 |
/** |
36 |
* the InfoTable wrapper that holds |
37 |
* all fields. |
38 |
*/ |
39 |
var $_infotable = NULL; |
40 |
|
41 |
|
42 |
function StandardFormContent($title, $cancel_action=NULL, |
43 |
$width="100%") { |
44 |
$this->FormContent($width, $cancel_action); |
45 |
$this->set_form_title( $title ); |
46 |
//each form has a confirmation |
47 |
$this->set_confirm(TRUE); |
48 |
} |
49 |
|
50 |
/** |
51 |
* this method sets the form title |
52 |
* which is used to wrap the entire form |
53 |
* |
54 |
* @param string - the form title |
55 |
*/ |
56 |
function set_form_title($title) { |
57 |
$this->_form_title = $title; |
58 |
} |
59 |
|
60 |
/** |
61 |
* this builds the main wrapper for the |
62 |
* form fields and ads the Save and Cancel buttons |
63 |
* |
64 |
* @param array - the form data |
65 |
* @param array - the form error fields (if any) |
66 |
* @return InfoTable widget object |
67 |
*/ |
68 |
function form() { |
69 |
$title = $this->_form_title._HTML_SPACE; |
70 |
$title .="( ".$this->_required_field_marker." ".$this->_required_field_text." )"; |
71 |
$this->_infotable = new InfoTable($title, $this->_width); |
72 |
$this->_infotable->set_cellpadding(0); |
73 |
|
74 |
//ok call the Child class to add the |
75 |
//form fields inside of form blocks |
76 |
$this->form_content(); |
77 |
|
78 |
$this->_infotable->add_row( $this->form_content_buttons() ); |
79 |
return $this->_infotable; |
80 |
} |
81 |
|
82 |
|
83 |
/** |
84 |
* Child class MUST override this |
85 |
* to provide the form fields |
86 |
* |
87 |
* @return object |
88 |
*/ |
89 |
function form_content() { |
90 |
user_error("StandardFormContent::form_content() - CHILD MUST OVERRIDE "); |
91 |
return NULL; |
92 |
} |
93 |
|
94 |
/** |
95 |
* This function is used to show an intermediary |
96 |
* confirmation page. Use this function to |
97 |
* show a confirmation of the data that was |
98 |
* submitted by the user. |
99 |
* This will get called after all of the |
100 |
* form data was successfully validated. |
101 |
* All of the form data will automatically |
102 |
* be created as hidden form fields. All you |
103 |
* have to do is show the data, and a confirm |
104 |
* submit button. |
105 |
* |
106 |
* @param string - the title for the table |
107 |
* @param boolean - show the action buttons? |
108 |
* @return mixed - either raw html, or some |
109 |
* container HTMLTag object. |
110 |
*/ |
111 |
function form_confirm( $title = "Form Confirmation", $show_buttons=TRUE ) { |
112 |
$title = $title._HTML_SPACE; |
113 |
$title .="( ".$this->_required_field_marker." ".$this->_required_field_text." )"; |
114 |
$table = new InfoTable($title, $this->_width); |
115 |
|
116 |
$this->build_confirm_table( $table ); |
117 |
|
118 |
//now add the confirmation button |
119 |
$td = new TDtag(array("colspan" => 2, |
120 |
"class" => "contentnovertical", |
121 |
"align" => "center"), |
122 |
$this->add_action("Confirm"), |
123 |
_HTML_SPACE, |
124 |
$this->add_action("Edit")); |
125 |
|
126 |
if ($this->_cancel_action) { |
127 |
$td->add(_HTML_SPACE, $this->add_cancel()); |
128 |
} |
129 |
|
130 |
if ($show_buttons) { |
131 |
$table->add_row( $td ); |
132 |
} |
133 |
|
134 |
return $table; |
135 |
} |
136 |
|
137 |
|
138 |
/** |
139 |
* This method handles the form action. |
140 |
* |
141 |
* @return boolean TRUE = success |
142 |
* FALSE = failed. |
143 |
*/ |
144 |
function form_action() { |
145 |
switch ($this->get_action()) { |
146 |
case "Edit": |
147 |
return FALSE; |
148 |
break; |
149 |
|
150 |
case "Confirm": |
151 |
return $this->confirm_action(); |
152 |
break; |
153 |
} |
154 |
} |
155 |
|
156 |
/** |
157 |
* This method is responsible for handling the |
158 |
* confirmation page's Confirm action. |
159 |
*/ |
160 |
function confirm_action() { |
161 |
user_error("FormContent::confirm_action() - Child class must override"); |
162 |
return FALSE; |
163 |
} |
164 |
|
165 |
|
166 |
/** |
167 |
* This function is used to build the standard |
168 |
* buttons for a form. |
169 |
* |
170 |
* @return ButtonPanel |
171 |
*/ |
172 |
function form_content_buttons() { |
173 |
$div = new DIVtag( array("style" => "background-color: #eeeeee;". |
174 |
"padding-top:5px;padding-bottom:5px", |
175 |
"align"=>"center", "nowrap"), |
176 |
$this->add_action("Save"), |
177 |
_HTML_SPACE, |
178 |
$this->add_cancel() ); |
179 |
return $div; |
180 |
} |
181 |
|
182 |
|
183 |
/** |
184 |
* This function is used to add a block of |
185 |
* form fields inside a table to this form. |
186 |
* This table will automatically get wrapped |
187 |
* inside a fieldset with a legend tag |
188 |
* to label the block |
189 |
* |
190 |
* @param string - the title for the fieldset |
191 |
* @param TABLEtag - the form fields inside a table |
192 |
*/ |
193 |
function add_form_block( $title=NULL, &$table ) { |
194 |
$this->_infotable->add_row( $this->build_form_block( $title, $table ) ); |
195 |
} |
196 |
|
197 |
|
198 |
/** |
199 |
* this builds a fieldset and legend and adds the |
200 |
* form table to it. |
201 |
* |
202 |
* @param string - the legend string |
203 |
* @param TABLEtag - the form fields in a table |
204 |
* @return FIELDSETtag |
205 |
*/ |
206 |
function &build_form_block( $title=NULL, &$content ) { |
207 |
$div = &$this->_div_wrapper( ); |
208 |
|
209 |
if ($title != NULL) { |
210 |
$fs = html_fieldset( $title ); |
211 |
$fs->add_reference( $content ); |
212 |
$div->add_reference( $fs ); |
213 |
} else { |
214 |
$div->add_reference( $content ); |
215 |
} |
216 |
return $div; |
217 |
} |
218 |
|
219 |
function &_div_wrapper() { |
220 |
$div = html_div(); |
221 |
$div->set_style("background-color: #eeeeee;padding:5px;"); |
222 |
return $div; |
223 |
} |
224 |
|
225 |
function _form_content_table($width="100%", $border=0, $cellspacing=0, |
226 |
$cellpadding=3) { |
227 |
$table = html_table($width,$border,$cellspacing,$cellpadding); |
228 |
return $table; |
229 |
} |
230 |
} |
231 |
?> |