root/branches/gettext/examples/example_element_file.php

Revision 394, 2.9 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      session_start();
16     
17     /**
18      * Main examples prepend file, needed *only* for the examples framework!
19      */
20     include_once 'patExampleGen/prepend.php';
21     $exampleGen->displayHead( 'Example' );
22
23     
24     // EXAMPLE START ------------------------------------------------------
25
26     /**
27      * main patForms class
28      */
29     require_once $neededFiles['patForms'];
30     
31     /**
32      * patErrorManager class
33      */
34     require_once $neededFiles['patErrorManager'];
35
36     /**
37      * localisation stuff
38      */
39     require_once $neededFiles['patI18n_configure'];
40
41     
42     // element definitions for this example
43     $elementsDefinition = array(
44         'testfile' => array(
45             'type' => 'File',
46             'attributes' => array(
47                 'id'            =>    'testfile',
48                 'required'        =>    'yes',
49                 'display'        =>    'yes',
50                 'edit'            =>    'yes',
51                 'title'            =>    'File upload',
52                 'label'            =>    'File upload',
53                 'description'    =>    'Upload a file of your choice...',
54                 'uploaddir'        =>    './fileupload',
55                 'overwrite'        =>    'no',
56                 'usesession'    =>    'yes',
57                 'maxsize'        =>    900000,
58                 //'tempdir'        =>    '/tmp_does:not:exist'
59                 //'permissions'    =>    0666,
60                 //'replacename'    =>    'i/[^a-z0-9]\./_',
61                 'mimetype'        =>    array( 'image/*', 'image/png' ),
62             ),
63         ),
64         'teststring' => array(
65             'type' => 'String',
66             'attributes' => array(
67                 'required'        =>    'yes',
68                 'display'        =>    'yes',
69                 'edit'            =>    'yes',
70                 'label'            =>    'Test string',
71                 'title'            =>    'Test string',
72                 'description'    =>    'Enter some text here and test some validation errors. Min length: [ELEMENT_MINLENGTH], Max length: [ELEMENT_MAXLENGTH]',
73                 'default'        =>    'x',
74                 'maxlength'        =>    '15',
75                 'minlength'        =>    '2',
76             ),
77         ),
78     );
79     
80     // create the form
81     $form    =&    patForms::createForm( $elementsDefinition, array( 'name' => 'myForm', 'enctype' => 'multipart/form-data' ) );
82     
83     // create the needed renderer
84     $renderer    =&    patForms::createRenderer( "Array" );
85     
86     // set the renderer
87     $form->setRenderer( $renderer );
88     
89     // use auto-validation
90     $form->setAutoValidate( 'save' );
91
92     // serialize the elements
93     $elements    =    $form->renderForm();
94
95     // ERROR DISPLAY ------------------------------------------------------
96     // ask the form if it has been submitted and display errors. For
97     // convenience and also to keep the examples easy to understand, all
98     // the following examples will use teh helper methods of the examples
99     // framework to display the errors and the form.
100     if( $form->isSubmitted() )
101     {
102         displayErrors( $form ); // see patExampleGen/customFunctions.php
103     }
104
105     // DISPLAY FORM ------------------------------------------------------
106     displayForm( $form, $elements ); // see patExampleGen/customFunctions.php
107
108     
109     
110     // EXAMPLE END ------------------------------------------------------
111     $exampleGen->displayFooter();
112 ?>
113
114
Note: See TracBrowser for help on using the browser.