| 1 | jonen | 1.1 | <?php | 
| 2 |  |  |  | 
| 3 |  |  | /** | 
| 4 |  |  | * This example illustrates the use of the | 
| 5 |  |  | * NavTable widget. | 
| 6 |  |  | * | 
| 7 |  |  | * | 
| 8 |  |  | * $Id: form2.php,v 1.3 2003/02/20 23:57:09 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 |  |  | $this->add_element( 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 |  |  |  | 
| 98 |  |  | //build a large textarea | 
| 99 |  |  | $this->add_element( new FETextArea("Comment", TRUE, "400px", "100px" ) ); | 
| 100 |  |  |  | 
| 101 |  |  | $this->add_hidden_element( "foo" ); | 
| 102 |  |  | } | 
| 103 |  |  |  | 
| 104 |  |  | /** | 
| 105 |  |  | * This method is called only the first time the form | 
| 106 |  |  | * page is hit. | 
| 107 |  |  | */ | 
| 108 |  |  | function form_init_data() { | 
| 109 |  |  | //Pull some valies from the DB | 
| 110 |  |  | //and set the initial values of some of the | 
| 111 |  |  | //form fields. | 
| 112 |  |  | // | 
| 113 |  |  | //In this example we just hard code some | 
| 114 |  |  | //initial values | 
| 115 |  |  | $this->set_element_value("First Name", "testing"); | 
| 116 |  |  |  | 
| 117 |  |  | //set a few of the checkboxlist items as checked. | 
| 118 |  |  | $this->set_element_value("List", array("bar","slerm",1)); | 
| 119 |  |  |  | 
| 120 |  |  | //change the value of the hidden form field | 
| 121 |  |  | $this->set_hidden_element_value("foo", "hemna"); | 
| 122 |  |  | } | 
| 123 |  |  |  | 
| 124 |  |  | /** | 
| 125 |  |  | * This method is called by the StandardFormContent object | 
| 126 |  |  | * to allow you to build the 'blocks' of fields you want to | 
| 127 |  |  | * display.  Each form block will live inside a fieldset tag | 
| 128 |  |  | * with the a title. | 
| 129 |  |  | * | 
| 130 |  |  | * In this example we have 2 form 'blocks'. | 
| 131 |  |  | */ | 
| 132 |  |  | function form_content() { | 
| 133 |  |  | $this->add_form_block("User Info", $this->_user_info() ); | 
| 134 |  |  | $this->add_form_block("Optional", $this->_optional_info() ); | 
| 135 |  |  | } | 
| 136 |  |  |  | 
| 137 |  |  | /** | 
| 138 |  |  | * This private method builds the table that holds | 
| 139 |  |  | * the 'user' form fields' | 
| 140 |  |  | * | 
| 141 |  |  | */ | 
| 142 |  |  | function &_user_info() { | 
| 143 |  |  | $table = &html_table($this->_width,0,2); | 
| 144 |  |  | $table->add_row($this->element_label("First Name"), | 
| 145 |  |  | $this->element_form("First Name")); | 
| 146 |  |  |  | 
| 147 |  |  | $table->add_row($this->element_label("Email Address"), | 
| 148 |  |  | $this->element_form("Email Address")); | 
| 149 |  |  |  | 
| 150 |  |  | $table->add_row($this->element_label("Password"), | 
| 151 |  |  | $this->element_form("Password")); | 
| 152 |  |  |  | 
| 153 |  |  | $table->add_row($this->element_label("Confirm Password"), | 
| 154 |  |  | $this->element_form("Confirm Password")); | 
| 155 |  |  |  | 
| 156 |  |  | return $table; | 
| 157 |  |  | } | 
| 158 |  |  |  | 
| 159 |  |  | /** | 
| 160 |  |  | * This private method builds the table that holds | 
| 161 |  |  | * the 'optional' form fields' | 
| 162 |  |  | * | 
| 163 |  |  | */ | 
| 164 |  |  | function &_optional_info() { | 
| 165 |  |  | $table = &html_table($this->_width,0,2); | 
| 166 |  |  |  | 
| 167 |  |  | $table->add_row($this->element_label("List"), | 
| 168 |  |  | $this->element_form("List")); | 
| 169 |  |  |  | 
| 170 |  |  | $table->add_row($this->element_label("Comment"), | 
| 171 |  |  | $this->element_form("Comment")); | 
| 172 |  |  |  | 
| 173 |  |  | return $table; | 
| 174 |  |  | } | 
| 175 |  |  |  | 
| 176 |  |  | /** | 
| 177 |  |  | * This method gets called after the FormElement data has | 
| 178 |  |  | * passed the validation, and has been confirmed. This | 
| 179 |  |  | * enables you to validate the data against some backend | 
| 180 |  |  | * mechanism, say a DB. | 
| 181 |  |  | * | 
| 182 |  |  | */ | 
| 183 |  |  | function form_backend_validation() { | 
| 184 |  |  | //HARD CODE an error here to show how to show an error | 
| 185 |  |  | //and that it will prevent the confirm_action() method | 
| 186 |  |  | //from being called | 
| 187 |  |  | $this->add_error("First Name", "Duplicate!!  You suck!"); | 
| 188 |  |  | return FALSE; | 
| 189 |  |  | } | 
| 190 |  |  |  | 
| 191 |  |  | /** | 
| 192 |  |  | * This method will get called after all validation has | 
| 193 |  |  | * passed, and the confirmation has been accepted. | 
| 194 |  |  | * | 
| 195 |  |  | * This is where u save the info to the DB. | 
| 196 |  |  | */ | 
| 197 |  |  | function confirm_action() { | 
| 198 |  |  | //$this->set_action_message("WOO!"); | 
| 199 |  |  | return TRUE; | 
| 200 |  |  | } | 
| 201 |  |  | } | 
| 202 |  |  |  | 
| 203 |  |  |  | 
| 204 |  |  | $page = new Form2Page("Form Example 2"); | 
| 205 |  |  | print $page->render(); | 
| 206 |  |  | ?> |