root/trunk/examples/example_element_file.php

Revision 355, 2.8 kB (checked in by gerd, 3 years ago)

commited changes from rev 354 to trunk, fixed #208 and #209 ...

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