root/branches/gettext/examples/example_datasrc_object.php

Revision 394, 3.6 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         'area' => array(
43             'type' => 'Enum',
44             'attributes' => array(
45                 'required'        =>    'yes',
46                 'display'        =>    'yes',
47                 'edit'            =>    'yes',
48                 'label'            =>    'Area',
49                 'title'            =>    'Area',
50                 'style'            =>    'width:200px;',
51                 'description'    =>    'Choose the area to access here.',
52                 'values'        =>    array(),
53             ),
54         ),
55     );
56     
57     // create the form
58     $form    =&    patForms::createForm( $elementsDefinition, array( 'name' => 'myForm' ) );
59     
60     
61     // DATASOURCE SETUP ------------------------------------------------------
62     /**
63      * Very simple example for a datasource class for patForms elements that support
64      * external data sources, like the Enum element.
65      *
66      * $Id$
67      *
68      * @access        public
69      * @package        patForms
70      * @subpackage    Examples
71      * @author        Sebastian Mordziol <argh@php-tools.net>
72      * @license        LGPL, see license.txt for details
73      * @link        http://www.php-tools.net
74      * @see            example.php
75      */
76     class exampleDatasrc
77     {
78         var $values    =    array(
79             array(   
80                 "label" => "Please select...",
81                 "value"    =>    "",
82             ),
83             array(   
84                 "label" => "-----------",
85                 "value"    =>    "",
86             ),
87             array(   
88                 "label" => "Private Area",
89                 "value"    =>    "a1",
90             ),
91             array(   
92                 "label" => "Area 51",
93                 "value"    =>    "a2",
94             ),
95             array(   
96                 "label" => "Secluded experimental Mojave Area",
97                 "value"    =>    "a3",
98             ),
99         );
100         
101        /**
102         * method for retrieving the values for the element, has to return them as
103         * key => value pairs in an array.
104         *
105         * @access    public
106         * @return    array    $values    The values for the element.
107         */
108         function getValues()
109         {
110             return $this->values;
111         }
112     }
113     
114
115     // get the element
116     $el =& $form->getElementByName( 'area' );
117     
118     // instantiate the example data source
119     $datasrcObject    =    new exampleDatasrc;
120     
121     // tell the element to use the datasource object
122     $el->setDataSource( $datasrcObject );
123
124
125     // PROCESS FORM ------------------------------------------------------
126
127     // create the needed renderer
128     $renderer    =&    patForms::createRenderer( "Array" );
129     
130     // set the renderer
131     $form->setRenderer( $renderer );
132     
133     // use auto-validation
134     $form->setAutoValidate( 'save' );
135
136     // serialize the elements
137     $elements    =    $form->renderForm();
138     
139     
140     // ERROR DISPLAY ------------------------------------------------------
141     // ask the form if it has been submitted and display errors. For
142     // convenience and also to keep the examples easy to understand, all
143     // the following examples will use teh helper methods of the examples
144     // framework to display the errors and the form.
145     if( $form->isSubmitted() )
146     {
147         displayErrors( $form ); // see patExampleGen/customFunctions.php
148     }
149
150     // DISPLAY FORM ------------------------------------------------------
151     displayForm( $form, $elements ); // see patExampleGen/customFunctions.php
152
153
154     
155     
156     // EXAMPLE END ------------------------------------------------------
157     $exampleGen->displayFooter();
158 ?>
Note: See TracBrowser for help on using the browser.