[Phphtmllib-devel] phphtmllib/examples form3.php,NONE,1.1 example9.php,1.1,1.2
Status: Beta
Brought to you by:
hemna
From: <cu...@us...> - 2004-03-09 06:32:21
|
Update of /cvsroot/phphtmllib/phphtmllib/examples In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28010 Modified Files: example9.php Added Files: form3.php Log Message: fixed comment in example9.php form3 is is a new, beta quality example. Walt when you get a chance could you look over form3.php? The idea of this example is to list all available form elements. I put a couple of questions in the comments of the form setup of things I don't understand (like how to set the default value on radio groups). Also I don't know the effect of having the form upload... Maybe there should just be a bogus error that will never pass so the form upload will not have to be handled? culley --- NEW FILE: form3.php --- <?php /** * This is an unrealistic example form that uses all available form elements. * No items have explicitly been marked as required, enabling you to test * individual elements by entering good data or garbage and seeing the result. * * $Id: form3.php,v 1.1 2004/03/09 06:15:21 culley Exp $ * * @author Culley Harrelson <cu...@fa...> * @package phpHtmlLib * @subpackage form-examples * @version 1.0.0 * */ // Include the phphtmllib libraries $phphtmllib = $_SERVER["DOCUMENT_ROOT"] . "/phphtmllib"; include_once("$phphtmllib/includes.inc"); // Include the Form Processing objects include_once($phphtmllib."/form/includes.inc"); //use the class we defined from //Example 3. include_once($phphtmllib."/examples/MyLayoutPage.inc"); /** * A simple Page Layout object child. this came from Example 3. * * @author Culley Harrelson <cu...@fa...> * @package phpHtmlLib * @subpackage form-examples * */ class Form3Page extends MyLayoutPage { function content_block() { //build the FormProcessor, and add the //Form content object that the FormProcessor //will use. Make the width of the form 95% return new FormProcessor(new SampleForm('95%')); } } /** * This is the Class that handles the building of the Form itself. It creates * the Form Elements inside the form_init_elements() method. * * @author Culley Harrelson <cu...@fa...> * @package phpHtmlLib * @subpackage form-examples * */ class SampleForm extends FormContent { // {{{ /** * This method gets called EVERY time the object is created. It is used to * build all of the FormElement objects used in this Form. * */ function form_init_elements() { // we want an confirmation page for this form. $this->set_confirm(); // now start to add the Form Elements that will be used in this form. // FEButton (label $label, string $value, [string $action = NULL], // [int $width = NULL], [int $height = NULL]) $this->add_element(new FEButton("FEButton Label", 'button-value', 'javascript-action')); // FECheckBox (label $label, string $text) $this->add_element(new FECheckBox("FECheckBox Label", 'checkbox-text')); // FEDataList (string $label, [boolean $required = TRUE], [int $width // = NULL], [int $height = NULL], [array $data_list = array()]) $list = new FECheckBoxList("FECheckBoxList label", FALSE, "200px", "80px", array("Testing 123" => "foo", "my value is bar" => "bar", "Somone's test" => "blah", "Slerm" => "slerm", "my value is hat" => "hat", "One" => 1)); $list->disable_item("Testing 123"); $this->add_element($list); // FEComboListBox (string $label, [boolean $required = TRUE], [int // $width = "200px"], [int $height = "100px"], [array $from_data_list = // array()], [array $to_data_list = array()]) $combo_list = new FEComboListBox("FEComboListBox Label", false, '300px', '100px', array('one' => 1, 'two' => 2), array('three' => 3, 'four' => 4)); $combo_list->set_to_label('this is the to label'); $combo_list->set_from_label('this is the from label'); $this->add_element($combo_list); // FEConfirmActionButton (mixed $label, mixed $value, [mixed $message // = NULL], [mixed $width = NULL], [mixed $height = NULL]) $this->add_element(new FEConfirmActionButton("FEConfirmActionButton label", 'click me for a javascript confirmation', 'Are you sure?')); // the constructor for FEPassword and FEConfirmPassword are the same as FEText $this->add_element(new FEPassword("FEPassword label", false, "200px")); $confirm = new FEConfirmPassword("FEConfirmPassword label", false, "200px"); // add the password FormElement to the ConfirmPassword FormElement so // we can make sure they match. $confirm->password($password); $this->add_element($confirm); // These elements have the same constructor as FEText $this->add_element(new FEDomainName("FEDomainName label", false, "200px")); $this->add_element(new FEEmail("FEEmail label", false, "200px")); $this->add_element(new FEEmailMany("FEEmailMany label (comma separated)", false, "400px")); // What do we do with FEError? // $this->add_element(new FEError("FEError label", 'error message')); // file upload $file = new FEFile("FEFile label", false, "200px"); $file->add_valid_type('image/gif'); $file->add_valid_type('image/jpeg'); $file->set_max_size(1024 * 2); $this->add_element($file); // FEHidden (mixed $label, [mixed $value = NULL]) $this->add_element(new FEHidden("FEHidden label", 'the hidden value')); // FEHostNameWithPort (label $label, [bool $required = TRUE], [int // $width = NULL], [int $maxlength = NULL], [bool $seperate_port = // FALSE]) $this->add_element(new FEHostNameWithPort("FEHostNameWithPort label", false)); // Same constructor as FEText $this->add_element(new FEIPAddress("FEIPAddress label", false, "200px")); // Same constructor as FEHostNameWithPort $this->add_element(new FEIPAddressWithPort("FEIPAddressWithPort label", false)); $list_box = new FEListBox('FEListBox label', false, '200px', '100px'); $list_box->set_list_data(array('one' => 1, 'two' => 2, 'three' => 3, 'four' => 4)); $this->add_element($list_box); // does this matter on the back end? How is this different from // FEListBox? $list_box = new FEMultiListBox('FEMultiListBox label', false, '200px', '100px'); $list_box->set_list_data(array('one' => 1, 'two' => 2, 'three' => 3, 'four' => 4)); $this->add_element($list_box); // Same constructor as FEText $this->add_element(new FEName("FEName label", false, "200px")); $nested_list_box = new FENestedListBox('FENestedListBox label', false, '200px', '100px'); $data = array("Test" => 1, "Foo" => array("value" => 2, "items" => array("Blah" => 3, "php" => 4)), "Bar" => array("value" => 5, "items" => array("testing" => array("value" => 6, "items" => array("ugh" => 7)), "again" => 8))); $nested_list_box->set_list_data($data); $this->add_element($nested_list_box); // Same constructor as FEText $this->add_element(new FENumber("FENumber label", false, "200px")); $this->add_element(new FENumberFloat("FENumberFloat label", false, "200px")); $this->add_element(new FENumberFloat("FENumberFloat label", false, "200px")); // FENumberInRange (label $label, [bool $required = TRUE], [int $width // = NULL], [int $maxlength = NULL], int $min, [int $max = 100], // [boolean $label_flag = TRUE]) $this->add_element(new FENumberInRange("FENumberInRange label", false, "200px", null, 1, 10)); // Same constructor as FEText $this->add_element(new FENumberPrice("FENumberPrice label", false, "200px")); // FERadioGroup (label $label, [array $data_list = array()]) // how do we set a default value? throws you to the top of the screen // and addss a # in firefox when clicked? $this->add_element(new FERadioGroup("FERadioGroup label", array('one' => 1, 'two' => 2, 'three' => 3, 'four' => 4))); // add constructor label here. $this->add_element( new FERegEx("FERegEx label", false, '200px', 3, '/^1[a-z]T$/', 'This field must equal 1[a-z]T') ); $this->add_element(new FEText("FEText label", false, "200px")); // FETextArea (label $label, [bool $required = TRUE], int $rows, int // $cols, [int $width = NULL], [int $height = NULL], [int // $limit_char_count = -1]) $this->add_element(new FETextArea("FETextArea label", false, 10, 50, null, 300)); // FEUnitedStates (string $label, [boolean $required = TRUE], [int // $width = NULL], [int $height = NULL], array 4) $this->add_element(new FEUnitedStates("FEUnitedStates label", false)); // Same constructor as FEText $this->add_element(new FEUrl("FEUrl label", false, "200px")); $this->add_element(new FEUrlStrict("FEUrlStrict label", false, "200px")); // FEYesNoListBox (label $label, [bool $required = TRUE], [array // $width = NULL], [int $height = NULL], [string $yes_value = "yes"], // [string $no_value = "no"]) $this->add_element(new FEYesNoListBox("FEYesNoListBox label", false)); // FEYesNoRadioGroup (label $label, [bool $required = TRUE], [string // $yes_value = "yes"], [string $no_value = "no"]) // how do you set the default? $this->add_element(new FEYesNoRadioGroup("FEYesNoRadioGroup label", false)); // FEZipcode (label $label, [bool $required = false], [int $width = // NULL], [int $maxlength = 5]) $this->add_element(new FEZipcode("FEZipcode label", false)); // FESubmitButton (label $label, string $value, [int $width = NULL], // [int $height = NULL]) $this->add_element(new FESubmitButton("FESubmitButton label", 'submit button value')); // not used: // FEBoxElement - container? // FEDataList - container? // FEError - how to use? } /** * This method is called only the first time the form page is hit. This * enables u to query a DB and pre populate the FormElement objects with * data. * */ function form_init_data() { } /** * This is the method that builds the layout of where the FormElements will * live. You can lay it out any way you like. * */ function form() { $table = &html_table($this->_width,0,0,2); // add each element to the form as it was included above foreach(array_keys($this->_elements) as $label) { $table->add_row($this->element_label($label), $this->element_form($label)); } return $table; } /** * This method gets called after the FormElement data has passed the * validation. This enables you to validate the data against some backend * mechanism, say a DB. * */ function form_backend_validation() { return TRUE; } /** * This method is called ONLY after ALL validation has passed. This is the * method that allows you to do something with the data, say insert/update * records in the DB. * */ function form_action() { $this->set_action_message("WOO!"); return TRUE; } } //}}} $page = new Form3Page("Form Example 3"); print $page->render(); ?> |