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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.4 - (show annotations)
Thu Aug 11 14:09:26 2005 UTC (18 years, 11 months ago) by jonen
Branch: MAIN
CVS Tags: HEAD
Changes since 1.3: +9 -3 lines
+ updated to version 2.5.3

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.2.2 2005/05/12 01:24:02 hemna Exp $
12 *
13 * @author Walter A. Boring IV <waboring@newsblob.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
114 //only show this if we aren't readonly
115 //if we are in read only mode...required doesn't make sense
116 if (!$this->is_readonly()) {
117 $title .="( ".$this->_required_field_marker." ".$this->_required_field_text." )";
118 }
119
120 $table = new InfoTable($title, $this->_width);
121
122 $this->build_confirm_table( $table );
123
124 //now add the confirmation button
125 $td = new TDtag(array("colspan" => 2,
126 "class" => "contentnovertical",
127 "align" => "center"),
128 $this->add_action("Confirm"),
129 _HTML_SPACE,
130 $this->add_action("Edit"));
131
132 if ($this->_cancel_action) {
133 $td->add(_HTML_SPACE, $this->add_cancel());
134 }
135
136 if ($show_buttons) {
137 $table->add_row( $td );
138 }
139
140 return $table;
141 }
142
143
144 /**
145 * This method handles the form action.
146 *
147 * @return boolean TRUE = success
148 * FALSE = failed.
149 */
150 function form_action() {
151 switch ($this->get_action()) {
152 case "Edit":
153 return FALSE;
154 break;
155
156 case "Confirm":
157 return $this->confirm_action();
158 break;
159 }
160 }
161
162 /**
163 * This method is responsible for handling the
164 * confirmation page's Confirm action.
165 */
166 function confirm_action() {
167 user_error("FormContent::confirm_action() - Child class must override");
168 return FALSE;
169 }
170
171
172 /**
173 * This function is used to build the standard
174 * buttons for a form.
175 *
176 * @return ButtonPanel
177 */
178 function form_content_buttons() {
179 $div = new DIVtag( array("style" => "background-color: #eeeeee;".
180 "padding-top:5px;padding-bottom:5px",
181 "align"=>"center", "nowrap"),
182 $this->add_action("Save"),
183 _HTML_SPACE,
184 $this->add_cancel() );
185 return $div;
186 }
187
188
189 /**
190 * This function is used to add a block of
191 * form fields inside a table to this form.
192 * This table will automatically get wrapped
193 * inside a fieldset with a legend tag
194 * to label the block
195 *
196 * @param string - the title for the fieldset
197 * @param TABLEtag - the form fields inside a table
198 */
199 function add_form_block( $title=NULL, &$table ) {
200 $this->_infotable->add_row( $this->build_form_block( $title, $table ) );
201 }
202
203
204 /**
205 * this builds a fieldset and legend and adds the
206 * form table to it.
207 *
208 * @param string - the legend string
209 * @param TABLEtag - the form fields in a table
210 * @return FIELDSETtag
211 */
212 function &build_form_block( $title=NULL, &$content ) {
213 $div = &$this->_div_wrapper( );
214
215 if ($title != NULL) {
216 $fs = html_fieldset( $title );
217 $fs->add_reference( $content );
218 $div->add_reference( $fs );
219 } else {
220 $div->add_reference( $content );
221 }
222 return $div;
223 }
224
225 function &_div_wrapper() {
226 $div = html_div();
227 $div->set_style("background-color: #eeeeee;padding:5px;");
228 return $div;
229 }
230
231 function _form_content_table($width="100%", $border=0, $cellspacing=0,
232 $cellpadding=3) {
233 $table = html_table($width,$border,$cellspacing,$cellpadding);
234 return $table;
235 }
236 }
237 ?>

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