root/branches/gettext/examples/example_api_default_attributes.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:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1 <?php
2 /**
3  * Example showing how to set default attributes for all elements in a form.
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                 'label'            =>    'Username',
47                 'description'    =>    'Enter your username here. Maximum length: [ELEMENT_MAXLENGTH]',
48                 'title'            =>    'Username',
49             ),
50         ),
51         'password' => array(
52             'type' => 'String',
53             'attributes' => array(
54                 'required'        =>    'yes',
55                 'label'            =>    'Password',
56                 'type'            =>    'password',
57                 'description'    =>    'Enter your password here. Maximum length: [ELEMENT_MAXLENGTH]',
58                 'title'            =>    'Password',
59             )
60         ),
61     );
62     
63     // default attributes we want to use
64     $defaultAttributes = array(
65         'style'        =>    'width:100%',
66         'maxlength'    =>    '15',
67         'minlength'    =>    '4',
68     );
69     
70     // There are two ways to set the default attributes:
71     //
72     // 1. As a static function call (like we do here) before we create the form.
73     // 2. As a normal function call after creating the form.
74     //
75     // Here we have to use the static function call before creating the form, as
76     // we use the automatic element creation feature via the createForm() method,
77     // and the default attributes have to be set before any element is created.
78     patForms::setDefaultAttributes( $defaultAttributes );
79     
80     // create the form
81     $form    =&    patForms::createForm( $elementsDefinition, array( 'name' => 'myForm' ) );
82     
83     // use auto-validation
84     $form->setAutoValidate( 'save' );
85
86     // create the needed renderer
87     $renderer    =&    patForms::createRenderer( "Array" );
88     
89     // set the renderer
90     $form->setRenderer( $renderer );
91     
92     // serialize the elements using the array renderer
93     $elements    =    $form->renderForm();
94     
95     
96     // ERROR DISPLAY ------------------------------------------------------
97     // ask the form if it has been submitted and display errors
98     if( $form->isSubmitted() )
99     {
100         displayErrors( $form ); // see patExampleGen/customFunctions.php
101     }
102
103     // DISPLAY FORM ------------------------------------------------------
104     displayForm( $form, $elements ); // see patExampleGen/customFunctions.php
105
106     
107
108     // example footer
109     $exampleGen->displayFooter();
110 ?>
111
Note: See TracBrowser for help on using the browser.