root/branches/gettext/examples/example_attributefilter_test.php

Revision 394, 2.8 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         'username' => array(
41             'type' => 'String',
42             'attributes' => array(
43                 'required'        =>    'yes',
44                 'display'        =>    'yes',
45                 'edit'            =>    'yes',
46                 'label'            =>    'Username',
47                 'title'            =>    'Username',
48                 'default'        =>    '       String with spaces',
49                 'description'    =>    'Please enter your username here.',
50             ),
51         ),
52     );
53
54     // create the form
55     $form    =&    patForms::createForm( $elementsDefinition, array( 'name' => 'myForm' ) );
56
57     // create the needed renderer
58     $renderer    =&    patForms::createRenderer( "Array" );
59
60     // set the renderer
61     $form->setRenderer( $renderer );
62
63     // use auto-validation
64     $form->setAutoValidate( 'save' );
65
66     // create the test filter
67     $filter =& patForms::createAttributeFilter( 'Test' );
68
69     // get the element
70     $el =& $form->getElementByName( 'username' );
71
72     // apply the filter to the element
73     $el->applyAttributeFilter( $filter );
74     
75     // Why not apply the filter for a second time - just to play with it...
76     $el->applyAttributeFilter( $filter );
77
78     $el->setAttribute( 'description', 'This is the new description, altered by the attribute filter!' );
79
80     // serialize the elements
81     $elements    =    $form->renderForm();
82
83
84     // ERROR DISPLAY ------------------------------------------------------
85     // ask the form if it has been submitted and display errors. For
86     // convenience and also to keep the examples easy to understand, all
87     // the following examples will use teh helper methods of the examples
88     // framework to display the errors and the form.
89     if( $form->isSubmitted() )
90     {
91         displayErrors( $form ); // see patExampleGen/customFunctions.php
92     }
93
94     // DISPLAY FORM ------------------------------------------------------
95     displayForm( $form, $elements ); // see patExampleGen/customFunctions.php
96
97     // EXAMPLE END ------------------------------------------------------
98     $exampleGen->displayFooter();
99 ?>
Note: See TracBrowser for help on using the browser.