| 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.7 2003/02/20 23:28:18 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->_form_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($data, $err); |
| 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 |
* @param InfoTable object that is the wrapper |
| 88 |
* @param the form data array |
| 89 |
* @param the form errors (if any) |
| 90 |
*/ |
| 91 |
function form_content( &$data, &$err ) { |
| 92 |
user_error("StandardFormContent::form_content() - CHILD MUST OVERRIDE "); |
| 93 |
return NULL; |
| 94 |
} |
| 95 |
|
| 96 |
/** |
| 97 |
* This function is used to show an intermediary |
| 98 |
* confirmation page. Use this function to |
| 99 |
* show a confirmation of the data that was |
| 100 |
* submitted by the user. |
| 101 |
* This will get called after all of the |
| 102 |
* form data was successfully validated. |
| 103 |
* All of the form data will automatically |
| 104 |
* be created as hidden form fields. All you |
| 105 |
* have to do is show the data, and a confirm |
| 106 |
* submit button. |
| 107 |
* |
| 108 |
* @return mixed - either raw html, or some |
| 109 |
* container HTMLTag object. |
| 110 |
*/ |
| 111 |
function form_confirm( ) { |
| 112 |
$title = "Form Confirmation"._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 |
$table->add_row( $td ); |
| 131 |
|
| 132 |
return $table; |
| 133 |
} |
| 134 |
|
| 135 |
|
| 136 |
/** |
| 137 |
* This method handles the form action. |
| 138 |
* |
| 139 |
* @return boolean TRUE = success |
| 140 |
* FALSE = failed. |
| 141 |
*/ |
| 142 |
function form_action() { |
| 143 |
switch ($this->get_action()) { |
| 144 |
case "Edit": |
| 145 |
return FALSE; |
| 146 |
break; |
| 147 |
|
| 148 |
case "Confirm": |
| 149 |
return $this->confirm_action(); |
| 150 |
break; |
| 151 |
} |
| 152 |
} |
| 153 |
|
| 154 |
/** |
| 155 |
* This method is responsible for handling the |
| 156 |
* confirmation page's Confirm action. |
| 157 |
*/ |
| 158 |
function confirm_action() { |
| 159 |
user_error("FormContent::confirm_action() - Child class must override"); |
| 160 |
return FALSE; |
| 161 |
} |
| 162 |
|
| 163 |
|
| 164 |
/** |
| 165 |
* This function is used to build the standard |
| 166 |
* buttons for a form. |
| 167 |
* |
| 168 |
* @return ButtonPanel |
| 169 |
*/ |
| 170 |
function form_content_buttons() { |
| 171 |
$div = new DIVtag( array("style" => "background-color: #eeeeee;". |
| 172 |
"padding-top:5px;padding-bottom:5px", |
| 173 |
"align"=>"center", "nowrap"), |
| 174 |
$this->add_action("Save"), |
| 175 |
_HTML_SPACE, |
| 176 |
$this->add_cancel() ); |
| 177 |
return $div; |
| 178 |
} |
| 179 |
|
| 180 |
|
| 181 |
/** |
| 182 |
* This function is used to add a block of |
| 183 |
* form fields inside a table to this form. |
| 184 |
* This table will automatically get wrapped |
| 185 |
* inside a fieldset with a legend tag |
| 186 |
* to label the block |
| 187 |
* |
| 188 |
* @param string - the title for the fieldset |
| 189 |
* @param TABLEtag - the form fields inside a table |
| 190 |
*/ |
| 191 |
function add_form_block( $title=NULL, &$table ) { |
| 192 |
$this->_infotable->add_row( $this->build_form_block( $title, $table ) ); |
| 193 |
} |
| 194 |
|
| 195 |
|
| 196 |
/** |
| 197 |
* this builds a fieldset and legend and adds the |
| 198 |
* form table to it. |
| 199 |
* |
| 200 |
* @param string - the legend string |
| 201 |
* @param TABLEtag - the form fields in a table |
| 202 |
* @return FIELDSETtag |
| 203 |
*/ |
| 204 |
function &build_form_block( $title=NULL, &$content ) { |
| 205 |
$div = &$this->_div_wrapper( ); |
| 206 |
|
| 207 |
if ($title != NULL) { |
| 208 |
$fs = html_fieldset( $title ); |
| 209 |
$fs->add_reference( $content ); |
| 210 |
$div->add_reference( $fs ); |
| 211 |
} else { |
| 212 |
$div->add_reference( $content ); |
| 213 |
} |
| 214 |
return $div; |
| 215 |
} |
| 216 |
|
| 217 |
function &_div_wrapper() { |
| 218 |
$div = html_div(); |
| 219 |
$div->set_style("background-color: #eeeeee;padding:5px;"); |
| 220 |
return $div; |
| 221 |
} |
| 222 |
|
| 223 |
function _form_content_table($width="100%", $border=0, $cellspacing=0, |
| 224 |
$cellpadding=3) { |
| 225 |
$table = html_table($width,$border,$cellspacing,$cellpadding); |
| 226 |
return $table; |
| 227 |
} |
| 228 |
} |
| 229 |
?> |