root/tags/RELEASE_0_9_0B1/examples/example_element_pool.php

Revision 117, 2.7 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         'mammalians' => array(
38             'type' => 'Pool',
39             'attributes' => array(
40                 'label'            =>    'Mammalians',
41                 'title'            =>    'Mammalians',
42                 'description'    =>    'List of mammals',
43                 'size'            =>    '10',
44                 'style'            =>    'width:150px;',
45                 'class'            =>    'pool',
46                 'candidates'    =>    array(
47                     array(   
48                         'label'    =>    'Ant',
49                         'value'    =>    'and',
50                      ),
51                     array(   
52                         'label'    =>    'Bee',
53                         'value'    =>    'bee',
54                      ),
55                     array(   
56                         'label'    =>    'Dog',
57                         'value'    =>    'deg',
58                      ),
59                     array(   
60                         'label'    =>    'Cat',
61                         'value'    =>    'cat',
62                      ),
63                     array(   
64                         'label'    =>    'Shark',
65                         'value'    =>    'shark',
66                      ),
67                     array(   
68                         'label'    =>    'Whale',
69                         'value'    =>    'whale',
70                      ),
71                 ),
72                 'candidatetitle'    =>    'Animals',
73                 'membertitle'        =>    'Mammalians',
74                 'titleclass'        =>    'pooltitle',
75                 'tooladd'            =>    'add mammalian',
76                 'toolremove'        =>    'remove animal',
77                 'toolclass'            =>    'pooltool',
78             ),
79         ),
80     );
81     
82     // create the form
83     $form =& patForms::createForm( $elementsDefinition, array( 'name' => 'myForm' ) );
84     
85     // create the needed renderer
86     $renderer =& patForms::createRenderer( "Array" );
87     
88     // set the renderer
89     $form->setRenderer( $renderer );
90     
91     // use auto-validation
92     $form->setAutoValidate( 'save' );
93
94     // serialize the elements
95     $elements    =    $form->renderForm();
96     
97     
98     // ERROR DISPLAY ------------------------------------------------------
99     // ask the form if it has been submitted and display errors. For
100     // convenience and also to keep the examples easy to understand, all
101     // the following examples will use teh helper methods of the examples
102     // framework to display the errors and the form.
103     if( $form->isSubmitted() )
104     {
105         displayErrors( $form ); // see patExampleGen/customFunctions.php
106     }
107
108     // DISPLAY FORM ------------------------------------------------------
109     displayForm( $form, $elements ); // see patExampleGen/customFunctions.php
110
111
112     
113     
114     // EXAMPLE END ------------------------------------------------------
115     $exampleGen->displayFooter();
116 ?>
Note: See TracBrowser for help on using the browser.