root/tags/RELEASE_0_9_0B1/examples/example_element_file.php

Revision 117, 2.8 kB (checked in by argh, 4 years ago)

Massive update of the examples collection; added the patExampleGen examples framework; commented all examples; reworked all the templates...

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