root/branches/gettext/examples/example_element_enum_optgroup.php

Revision 394, 3.5 kB (checked in by gerd, 1 year ago)

Switched to patI18n

  • removed all setLocale / getLocale functions from patForms, elements etc.
  • use patI18n::dgettext with textdomain "patForms"
  • added patI18n example
  • added helper script to setup patI18n
  • mended examples accordingly
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      * localisation stuff
36      */
37     require_once $neededFiles['patI18n_configure'];
38
39     
40     // element definitions for this example
41     $elementsDefinition = array(
42         'username' => array(
43             'type' => 'String',
44             'attributes' => array(
45                 'required'        =>    'yes',
46                 'display'        =>    'yes',
47                 'edit'            =>    'yes',
48                 'label'            =>    'Username',
49                 'title'            =>    'Username',
50                 'description'    =>    'Enter your username here. Maximum length: [ELEMENT_MAXLENGTH]',
51                 'default'        =>    'argh',
52                 'maxlength'        =>    '15',
53                 'minlength'        =>    '4',
54             ),
55         ),
56         'country' => array(
57             'type' => 'Enum',
58             'attributes' => array(
59                 'required'        =>    'yes',
60                 'display'        =>    'yes',
61                 'edit'            =>    'yes',
62                 'label'            =>    'Country',
63                 'title'            =>    'Country',
64                 'description'    =>    'Choose the country you are from.',
65                 'values'        =>    array(
66                     array(
67                         'label'  =>  'Europe',
68                         'values' =>  array(
69                                         array(
70                                             'label'    =>    'Germany',
71                                             'value'    =>    'de',
72                                         ),
73                                         array(
74                                             'label'    =>    'France',
75                                             'value'    =>    'fr',
76                                         )
77                                 )                     
78                         ),
79                     array(
80                         'label'  =>  'America',
81                         'values' =>  array(
82                                         array(
83                                             'label'    =>    'USA',
84                                             'value'    =>    'us',
85                                         ),
86                                         array(
87                                             'label'    =>    'Mexico',
88                                             'value'    =>    'mx',
89                                         ),                       
90                         )
91                     )
92                 ),
93             ),
94         ),
95     );
96     
97     // create the form
98     $form    =&    patForms::createForm( $elementsDefinition, array( 'name' => 'myForm' ) );
99     
100     // create the needed renderer
101     $renderer    =&    patForms::createRenderer( "Array" );
102     
103     // set the renderer
104     $form->setRenderer( $renderer );
105     
106     // use auto-validation
107     $form->setAutoValidate( 'save' );
108
109     // serialize the elements
110     $elements    =    $form->renderForm();
111     
112     
113     // ERROR DISPLAY ------------------------------------------------------
114     // ask the form if it has been submitted and display errors. For
115     // convenience and also to keep the examples easy to understand, all
116     // the following examples will use teh helper methods of the examples
117     // framework to display the errors and the form.
118     if( $form->isSubmitted() )
119     {
120         displayErrors( $form ); // see patExampleGen/customFunctions.php
121     }
122
123     // DISPLAY FORM ------------------------------------------------------
124     displayForm( $form, $elements ); // see patExampleGen/customFunctions.php
125
126
127     
128     
129     // EXAMPLE END ------------------------------------------------------
130     $exampleGen->displayFooter();
131 ?>
Note: See TracBrowser for help on using the browser.