root/trunk/examples/example_element_enum_optgroup.php

Revision 347, 3.4 kB (checked in by schst, 3 years ago)

Added experimental optgroup support to the Enum element

Line 
1 <?php
2 /**
3  * Example for the Enum element using optgroups
4  *
5  * $Id: example_element_enum.php 117 2004-08-26 13:08:37Z argh $
6  *
7  * @access        public
8  * @package        patForms
9  * @subpackage    Examples
10  * @author        Sebastian Mordziol <argh@php-tools.net>
11  * @license        LGPL, see license.txt for details
12  * @link        http://www.php-tools.net
13  */
14
15     /**
16      * Main examples prepend file, needed *only* for the examples framework!
17      */
18     include_once 'patExampleGen/prepend.php';
19     $exampleGen->displayHead( 'Example' );
20
21     
22     // EXAMPLE START ------------------------------------------------------
23
24     /**
25      * main patForms class
26      */
27     require_once $neededFiles['patForms'];
28     
29     /**
30      * patErrorManager class
31      */
32     require_once $neededFiles['patErrorManager'];
33
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',
49             ),
50         ),
51         'country' => array(
52             'type' => 'Enum',
53             'attributes' => array(
54                 'required'        =>    'yes',
55                 'display'        =>    'yes',
56                 'edit'            =>    'yes',
57                 'label'            =>    'Country',
58                 'title'            =>    'Country',
59                 'description'    =>    'Choose the country you are from.',
60                 'values'        =>    array(
61                     array(
62                         'label'  =>  'Europe',
63                         'values' =>  array(
64                                         array(
65                                             'label'    =>    'Germany',
66                                             'value'    =>    'de',
67                                         ),
68                                         array(
69                                             'label'    =>    'France',
70                                             'value'    =>    'fr',
71                                         )
72                                 )                     
73                         ),
74                     array(
75                         'label'  =>  'America',
76                         'values' =>  array(
77                                         array(
78                                             'label'    =>    'USA',
79                                             'value'    =>    'us',
80                                         ),
81                                         array(
82                                             'label'    =>    'Mexico',
83                                             'value'    =>    'mx',
84                                         ),                       
85                         )
86                     )
87                 ),
88             ),
89         ),
90     );
91     
92     // create the form
93     $form    =&    patForms::createForm( $elementsDefinition, array( 'name' => 'myForm' ) );
94     
95     // create the needed renderer
96     $renderer    =&    patForms::createRenderer( "Array" );
97     
98     // set the renderer
99     $form->setRenderer( $renderer );
100     
101     // use auto-validation
102     $form->setAutoValidate( 'save' );
103
104     // serialize the elements
105     $elements    =    $form->renderForm();
106     
107     
108     // ERROR DISPLAY ------------------------------------------------------
109     // ask the form if it has been submitted and display errors. For
110     // convenience and also to keep the examples easy to understand, all
111     // the following examples will use teh helper methods of the examples
112     // framework to display the errors and the form.
113     if( $form->isSubmitted() )
114     {
115         displayErrors( $form ); // see patExampleGen/customFunctions.php
116     }
117
118     // DISPLAY FORM ------------------------------------------------------
119     displayForm( $form, $elements ); // see patExampleGen/customFunctions.php
120
121
122     
123     
124     // EXAMPLE END ------------------------------------------------------
125     $exampleGen->displayFooter();
126 ?>
Note: See TracBrowser for help on using the browser.