Changeset 117 for trunk/examples/example_element_enum.php
- Timestamp:
- 08/26/04 15:08:37 (4 years ago)
- Files:
-
- trunk/examples/example_element_enum.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/examples/example_element_enum.php
r2 r117 1 1 <?php 2 2 /** 3 * patForms example for enum elements with a function as a datasource3 * Example for the Date element 4 4 * 5 5 * $Id$ … … 12 12 * @link http://www.php-tools.net 13 13 */ 14 ?>15 <html>16 <head>17 <title>formValidator example</title>18 <style>19 @import url( _styles.css );20 </style>21 </head>22 <body marginheight="10" marginwidth="10" leftmargin="10" rightmargin="10" topmargin="10" bottommargin="10">23 24 <div class="head"><b>patForms Element:</b> Enum</div>25 26 <form action="example_element_enum.php" method="get">27 28 <?php29 error_reporting( E_ALL );30 14 31 15 /** 32 * Main patForms element class16 * Main examples prepend file, needed *only* for the examples framework! 33 17 */ 34 require_once '../patForms/Element.php'; 18 include_once 'patExampleGen/prepend.php'; 19 $exampleGen->displayHead( 'Example' ); 20 35 21 22 // EXAMPLE START ------------------------------------------------------ 23 36 24 /** 37 * Enum elementclass25 * main patForms class 38 26 */ 39 include_once( "../patForms/Element/Enum.php" );40 27 require_once $neededFiles['patForms']; 28 41 29 /** 42 30 * patErrorManager class 43 31 */ 44 require_once 'pat/patErrorManager.php';32 require_once $neededFiles['patErrorManager']; 45 33 46 /** 47 * Helper functions needed by the patForms example files 48 */ 49 include_once( "_helperfunctions.php" ); 50 51 // create the attribute collection for the enum field, including 52 // default values list in case something goes wrong 53 $attributes = array( 54 'name' => 'area', 55 'required' => 'yes', 56 'style' => 'width:100%', 57 'display' => 'yes', 58 'edit' => 'yes', 59 'label' => 'Area', 60 'description' => 'Choose the area to access here.', 61 'position' => '3', 62 'accesskey' => 'C', 63 'size' => 'auto', 64 'title' => 'Area', 65 'values' => array( 66 array( 67 'label' => 'Please choose an area...', 68 'value' => '', 34 35 // element definitions for this example 36 $elementsDefinition = array( 37 'username' => array( 38 'type' => 'String', 39 'attributes' => array( 40 'required' => 'yes', 41 'display' => 'yes', 42 'edit' => 'yes', 43 'label' => 'Username', 44 'title' => 'Username', 45 'description' => 'Enter your username here. Maximum length: [ELEMENT_MAXLENGTH]', 46 'default' => 'argh', 47 'maxlength' => '15', 48 'minlength' => '4', 69 49 ), 70 array( 71 'label' => 'Very pretty area', 72 'value' => 'a01', 73 ), 74 array( 75 'label' => 'No-nonsense area', 76 'value' => 'a02', 50 ), 51 'area' => array( 52 'type' => 'Enum', 53 'attributes' => array( 54 'required' => 'yes', 55 'display' => 'yes', 56 'edit' => 'yes', 57 'label' => 'Area', 58 'title' => 'Area', 59 'description' => 'Choose the area to access here.', 60 'values' => array( 61 array( 62 'label' => 'Please choose an area...', 63 'value' => '', 64 ), 65 array( 66 'label' => 'Very pretty area', 67 'value' => 'a01', 68 ), 69 array( 70 'label' => 'No-nonsense area', 71 'value' => 'a02', 72 ), 73 ), 77 74 ), 78 75 ), 79 76 ); 77 78 // create the form 79 $form =& patForms::createForm( $elementsDefinition, array( 'name' => 'myForm' ) ); 80 81 // create the needed renderer 82 $renderer =& patForms::createRenderer( "Array" ); 83 84 // set the renderer 85 $form->setRenderer( $renderer ); 86 87 // use auto-validation 88 $form->setAutoValidate( 'save' ); 80 89 81 // create the enum element82 $el =& new patForms_Element_Enum( 'html');90 // serialize the elements 91 $elements = $form->renderForm(); 83 92 84 // set the attribute collection to use85 $el->setAttributes( $attributes );86 93 87 // check if form has been saved 88 if( isset( $_GET["save"] ) ) 94 // ERROR DISPLAY ------------------------------------------------------ 95 // ask the form if it has been submitted and display errors. For 96 // convenience and also to keep the examples easy to understand, all 97 // the following examples will use teh helper methods of the examples 98 // framework to display the errors and the form. 99 if( $form->isSubmitted() ) 89 100 { 90 // tell the element it has been submitted 91 $el->setSubmitted( true ); 92 93 // validate the element 94 if( !$el->validate() ) 95 { 96 echo "<b>patFormsElement Enum:</b> validation failed. Errors:<br>"; 97 echo "<pre>"; 98 print_r( $el->getValidationErrors() ); 99 echo "</pre>"; 100 } 101 else 102 echo "<b>patFormsElement Enum:</b> validation successful.<br><br>"; 101 displayErrors( $form ); // see patExampleGen/customFunctions.php 103 102 } 104 103 105 // retrieve the serialized content of the element 106 $html = $el->serialize(); 104 // DISPLAY FORM ------------------------------------------------------ 105 displayForm( $form, $elements ); // see patExampleGen/customFunctions.php 106 107 108 109 110 // EXAMPLE END ------------------------------------------------------ 111 $exampleGen->displayFooter(); 107 112 ?> 108 109 <fieldset><legend><b>Generated element</b></legend>110 <?php111 // display the element112 echo $attributes["label"]."<br>";113 echo "<div>".$html."</div>";114 echo "<i>".$attributes["description"]."</i><br><br>";115 ?>116 </fieldset><br>117 118 <input type="submit" name="save" value="Save element"/><br><br>119 120 <fieldset><legend><b>Element source code</b></legend>121 <?php displaySource( $html ); ?>122 </fieldset>123 124 </form>125 126 </body>127 </html>
