root/branches/gettext/examples/example_attributefilter_applyform.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:keywords set to "Id"
Line 
1 <?php
2 /**
3  * Example
4  *
5  * $Id$
6  *
7  * @package     patForms
8  * @subpackage  Examples
9  * @author      gERD Schaufelberger <gerd@php-tools.net>
10  * @license     LGPL, see license.txt for details
11  * @link        http://www.php-tools.net
12  */
13
14    /**
15     * Main examples prepend file, needed *only* for the examples framework!
16     */
17     include_once 'patExampleGen/prepend.php';
18     $exampleGen->displayHead( 'Example' );
19
20
21     // EXAMPLE START ------------------------------------------------------
22
23    /**
24     * main patForms class
25     */
26     require_once $neededFiles['patForms'];
27
28    /**
29     * patErrorManager class
30     */
31     require_once $neededFiles['patErrorManager'];
32     
33     /**
34      * localisation stuff
35      */
36     require_once $neededFiles['patI18n_configure'];
37
38     // element definitions for this example
39     $elementsDefinition = array(
40         'temperature' => array(
41             'type' => 'Number',
42             'attributes' => array(
43                 'required'      =>  'yes',
44                 'display'       =>  'yes',
45                 'edit'          =>  'yes',
46                 'label'         =>  'Temperature',
47                 'title'         =>  'Temperature',
48                 'default'       =>  13,
49                 'min'           =>  -50,
50                 'max'           =>  50,
51                 'description'   =>  'Temperature in degree Celsius',
52             ),
53         ),
54         'windforce' => array(
55             'type' => 'Number',
56             'attributes' => array(
57                 'required'      =>  'yes',
58                 'display'       =>  'yes',
59                 'edit'          =>  'yes',
60                 'label'         =>  'Wind Force',
61                 'title'         =>  'Wind Force',
62                 'default'       =>  1,
63                 'min'           =>  0,
64                 'max'           =>  10,
65                 'description'   =>  'Wind force in beauford',
66             ),
67         ),
68         'winddirection' => array(
69             'type' => 'String',
70             'attributes' => array(
71                 'required'      =>  'yes',
72                 'display'       =>  'yes',
73                 'edit'          =>  'yes',
74                 'label'         =>  'Wind Direction',
75                 'title'         =>  'Wind Direction',
76                 'default'       =>  'Nord',
77                 'description'   =>  'Where does the wind come from?',
78             ),
79         ),
80     );
81
82     // create the form
83     $form   =&  patForms::createForm( $elementsDefinition, array( 'name' => 'myForm' ) );
84
85     // create the needed renderer
86     $renderer   =&  patForms::createRenderer( "Array" );
87
88     // set the renderer
89     $form->setRenderer( $renderer );
90
91     // use auto-validation
92     $form->setAutoValidate( 'save' );
93
94     // create the test filter
95     $filter =& patForms::createAttributeFilter( 'Test' );
96
97     // apply filter to all form elements
98     $form->applyAttributeFilter( $filter );
99
100     // serialize the elements
101     $elements   =   $form->renderForm();
102
103
104     // ERROR DISPLAY ------------------------------------------------------
105     // ask the form if it has been submitted and display errors. For
106     // convenience and also to keep the examples easy to understand, all
107     // the following examples will use teh helper methods of the examples
108     // framework to display the errors and the form.
109     if( $form->isSubmitted() )
110     {
111         displayErrors( $form ); // see patExampleGen/customFunctions.php
112     }
113
114     // DISPLAY FORM ------------------------------------------------------
115     displayForm( $form, $elements ); // see patExampleGen/customFunctions.php
116
117     // EXAMPLE END ------------------------------------------------------
118     $exampleGen->displayFooter();
119 ?>
Note: See TracBrowser for help on using the browser.