| 1 | <?php | 
| 2 |  | 
| 3 | /** | 
| 4 | * This example illustrates the use of the | 
| 5 | * NavTable widget. | 
| 6 | * | 
| 7 | * | 
| 8 | * $Id: form2.php,v 1.9 2003/10/02 22:49:01 hemna Exp $ | 
| 9 | * | 
| 10 | * @author Walter A. Boring IV <waboring@buildabetterweb.com> | 
| 11 | * @package phpHtmlLib | 
| 12 | * @subpackage form-examples | 
| 13 | * @version 2.2.0 | 
| 14 | * | 
| 15 | */ | 
| 16 |  | 
| 17 | /** | 
| 18 | * Include the phphtmllib libraries | 
| 19 | * | 
| 20 | */ | 
| 21 | include("includes.inc"); | 
| 22 |  | 
| 23 | /** | 
| 24 | * Include the Form Processing objects | 
| 25 | * | 
| 26 | */ | 
| 27 | include_once($phphtmllib."/form/includes.inc"); | 
| 28 |  | 
| 29 |  | 
| 30 | //use the class we defined from | 
| 31 | //Example 3. | 
| 32 | include_once("MyLayoutPage.inc"); | 
| 33 |  | 
| 34 | /** | 
| 35 | * A simple Page Layout object child. | 
| 36 | * this came from Example 3. | 
| 37 | * | 
| 38 | * @author Walter A. Boring IV <waboring@buildabetterweb.com> | 
| 39 | * @package phpHtmlLib | 
| 40 | * @subpackage form-examples | 
| 41 | */ | 
| 42 | class Form2Page extends MyLayoutPage { | 
| 43 |  | 
| 44 | function content_block() { | 
| 45 | //build the FormProcessor, and add the | 
| 46 | //Form content object that the FormProcessor | 
| 47 | //will use. | 
| 48 | // | 
| 49 | //This uses the StandardFormContent object to build | 
| 50 | //and render the look/feel of the form.  It has a built | 
| 51 | //in mechanism for doing the form submit buttons, including | 
| 52 | //the Cancel action. | 
| 53 | //The title of this form is 'Testing'. | 
| 54 | //the cancel url to go to is http://www.newsblob.com | 
| 55 | //and the width of the form is 600 | 
| 56 | return new FormProcessor( new StandardAccountForm("Testing", | 
| 57 | "http://www.newsblob.com", | 
| 58 | 600)); | 
| 59 | } | 
| 60 | } | 
| 61 |  | 
| 62 | /** | 
| 63 | * A simple Page Layout object child. | 
| 64 | * this came from Example 3. | 
| 65 | * | 
| 66 | * @author Walter A. Boring IV <waboring@buildabetterweb.com> | 
| 67 | * @package phpHtmlLib | 
| 68 | * @subpackage form-examples | 
| 69 | */ | 
| 70 | class StandardAccountForm extends StandardFormContent { | 
| 71 |  | 
| 72 | /** | 
| 73 | * This method gets called EVERY time the object is | 
| 74 | * created | 
| 75 | */ | 
| 76 | function form_init_elements() { | 
| 77 | $this->add_element( new FEText("First Name", TRUE, 20) ); | 
| 78 |  | 
| 79 | $password = new FEPassword("Password", TRUE); | 
| 80 | $this->add_element( $password ); | 
| 81 |  | 
| 82 | $confirm = new FEConfirmPassword("Confirm Password", TRUE); | 
| 83 | $confirm->password( $password ); | 
| 84 | $this->add_element( $confirm ); | 
| 85 |  | 
| 86 | $this->add_element( new FEEmail("Email Address", TRUE, "200px") ); | 
| 87 |  | 
| 88 | //This will build a scrollable list of checkboxes. | 
| 89 | $list =  new FECheckBoxList("List", FALSE, | 
| 90 | "200px", "80px", | 
| 91 | array("Testing 123" => "foo", | 
| 92 | "What is this?" => "bar", | 
| 93 | "Somone's test" => "blah", | 
| 94 | "Slerm" => "slerm", | 
| 95 | "Flem" => "flom", | 
| 96 | "One" => 1)); | 
| 97 | $list->disable_item("Testing 123"); | 
| 98 | $this->add_element( $list ); | 
| 99 |  | 
| 100 |  | 
| 101 | $this->add_element( new FEListBox("Anrede", FALSE, "100px", NULL,array("Frau"=>0,"Herr"=>1)) ); | 
| 102 |  | 
| 103 | //build a large textarea | 
| 104 | $this->add_element( new FETextArea("Comment", TRUE, 20, 10,"400px", "100px" ) ); | 
| 105 |  | 
| 106 | $this->add_hidden_element( "foo" ); | 
| 107 |  | 
| 108 | $this->add_element( new FECheckBox ("Patient Contact1", "Daytime Phone") ); | 
| 109 | $this->add_element( new FECheckBox ("Patient Contact2", "Evening Phone") ); | 
| 110 | $this->add_element( new FECheckBox ("Patient Contact3", "Email") ); | 
| 111 |  | 
| 112 | } | 
| 113 |  | 
| 114 | /** | 
| 115 | * This method is called only the first time the form | 
| 116 | * page is hit. | 
| 117 | */ | 
| 118 | function form_init_data() { | 
| 119 | //Pull some valies from the DB | 
| 120 | //and set the initial values of some of the | 
| 121 | //form fields. | 
| 122 | // | 
| 123 | //In this example we just hard code some | 
| 124 | //initial values | 
| 125 | $this->set_element_value("First Name", "testing"); | 
| 126 |  | 
| 127 | //set a few of the checkboxlist items as checked. | 
| 128 | $this->set_element_value("List", array("bar","slerm",1)); | 
| 129 |  | 
| 130 | //change the value of the hidden form field | 
| 131 | $this->set_hidden_element_value("foo", "hemna"); | 
| 132 | } | 
| 133 |  | 
| 134 | /** | 
| 135 | * This method is called by the StandardFormContent object | 
| 136 | * to allow you to build the 'blocks' of fields you want to | 
| 137 | * display.  Each form block will live inside a fieldset tag | 
| 138 | * with the a title. | 
| 139 | * | 
| 140 | * In this example we have 2 form 'blocks'. | 
| 141 | */ | 
| 142 | function form_content() { | 
| 143 | $this->add_form_block("User Info", $this->_user_info() ); | 
| 144 | $this->add_form_block("Optional", $this->_optional_info() ); | 
| 145 | } | 
| 146 |  | 
| 147 | /** | 
| 148 | * This private method builds the table that holds | 
| 149 | * the 'user' form fields' | 
| 150 | * | 
| 151 | */ | 
| 152 | function &_user_info() { | 
| 153 | $table = &html_table($this->_width,0,2); | 
| 154 | $table->add_row($this->element_label("First Name"), | 
| 155 | $this->element_form("First Name")); | 
| 156 |  | 
| 157 | $table->add_row($this->element_label("Email Address"), | 
| 158 | $this->element_form("Email Address")); | 
| 159 |  | 
| 160 | $table->add_row($this->element_label("Password"), | 
| 161 | $this->element_form("Password")); | 
| 162 |  | 
| 163 | $table->add_row($this->element_label("Confirm Password"), | 
| 164 | $this->element_form("Confirm Password")); | 
| 165 |  | 
| 166 | return $table; | 
| 167 | } | 
| 168 |  | 
| 169 | /** | 
| 170 | * This private method builds the table that holds | 
| 171 | * the 'optional' form fields' | 
| 172 | * | 
| 173 | */ | 
| 174 | function &_optional_info() { | 
| 175 | $table = &html_table($this->_width,0,2); | 
| 176 |  | 
| 177 | $table->add_row($this->element_label("Anrede"), | 
| 178 | $this->element_form("Anrede")); | 
| 179 |  | 
| 180 | $table->add_row($this->element_label("List"), | 
| 181 | $this->element_form("List")); | 
| 182 |  | 
| 183 | $table->add_row($this->element_label("Comment"), | 
| 184 | $this->element_form("Comment")); | 
| 185 |  | 
| 186 | $td = new TDtag( array("colspan" => 2), | 
| 187 | $this->element_form("Patient Contact1"), | 
| 188 | $this->element_form("Patient Contact2"), | 
| 189 | $this->element_form("Patient Contact3") ); | 
| 190 |  | 
| 191 | $table->add_row( $td ); | 
| 192 |  | 
| 193 | return $table; | 
| 194 | } | 
| 195 |  | 
| 196 | /** | 
| 197 | * This method gets called after the FormElement data has | 
| 198 | * passed the validation, and has been confirmed. This | 
| 199 | * enables you to validate the data against some backend | 
| 200 | * mechanism, say a DB. | 
| 201 | * | 
| 202 | */ | 
| 203 | function form_backend_validation() { | 
| 204 | //var_dump( $this->has_confirm() ); | 
| 205 | //HARD CODE an error here to show how to show an error | 
| 206 | //and that it will prevent the confirm_action() method | 
| 207 | //from being called | 
| 208 | $this->add_error("First Name", "Duplicate!!  You suck!"); | 
| 209 | return FALSE; | 
| 210 | } | 
| 211 |  | 
| 212 | /** | 
| 213 | * This method will get called after all validation has | 
| 214 | * passed, and the confirmation has been accepted. | 
| 215 | * | 
| 216 | * This is where u save the info to the DB. | 
| 217 | */ | 
| 218 | function confirm_action() { | 
| 219 | //$this->set_action_message("WOO!"); | 
| 220 | return TRUE; | 
| 221 | } | 
| 222 | } | 
| 223 |  | 
| 224 |  | 
| 225 | $page = new Form2Page("Form Example 2"); | 
| 226 | print $page->render(); | 
| 227 | ?> |