root/branches/gettext/examples/example_element_enum.php

Revision 394, 2.7 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
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1 <?php
2 /**
3  * Example for the Date element
4  *
5  * $Id$
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         'area' => array(
57             'type' => 'Enum',
58             'attributes' => array(
59                 'required'        =>    'yes',
60                 'display'        =>    'yes',
61                 'edit'            =>    'yes',
62                 'label'            =>    'Area',
63                 'title'            =>    'Area',
64                 'description'    =>    'Choose the area to access here.',
65                 'values'        =>    array(
66                     array(
67                         'label'    =>    'Please choose an area...',
68                         'value'    =>    '',
69                     ),
70                     array(
71                         'label'    =>    'Very pretty area',
72                         'value'    =>    'a01',
73                     ),
74                     array(
75                         'label'    =>    'No-nonsense area',
76                         'value'    =>    'a02',
77                     ),
78                 ),
79             ),
80         ),
81     );
82     
83     // create the form
84     $form    =&    patForms::createForm( $elementsDefinition, array( 'name' => 'myForm' ) );
85     
86     // create the needed renderer
87     $renderer    =&    patForms::createRenderer( "Array" );
88     
89     // set the renderer
90     $form->setRenderer( $renderer );
91     
92     // use auto-validation
93     $form->setAutoValidate( 'save' );
94
95     // serialize the elements
96     $elements    =    $form->renderForm();
97     
98     
99     // ERROR DISPLAY ------------------------------------------------------
100     // ask the form if it has been submitted and display errors. For
101     // convenience and also to keep the examples easy to understand, all
102     // the following examples will use teh helper methods of the examples
103     // framework to display the errors and the form.
104     if( $form->isSubmitted() )
105     {
106         displayErrors( $form ); // see patExampleGen/customFunctions.php
107     }
108
109     // DISPLAY FORM ------------------------------------------------------
110     displayForm( $form, $elements ); // see patExampleGen/customFunctions.php
111
112
113     
114     
115     // EXAMPLE END ------------------------------------------------------
116     $exampleGen->displayFooter();
117 ?>
Note: See TracBrowser for help on using the browser.