root/tags/RELEASE_0_9_0B1/examples/example_element_combobox.php

Revision 185, 2.7 kB (checked in by schst, 4 years ago)

very early version of a combobox

  • 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         'username' => array(
38             'type' => 'String',
39             'attributes' => array(
40                 'required'        =>    'yes',
41                 'display'        =>    'yes',
42                 'edit'            =>    'yes',
43                 'label'            =>    'Username',
44                 'title'            =>    'Username',
45                 'description'    =>    'Enter your username here. Maximum length: [ELEMENT_MAXLENGTH]',
46                 'default'        =>    'argh',
47                 'maxlength'        =>    '15',
48                 'minlength'        =>    '4',
49             ),
50         ),
51         'area' => array(
52             'type' => 'Combobox',
53             'attributes' => array(
54                 'required'        =>    'yes',
55                 'display'        =>    'yes',
56                 'edit'            =>    'yes',
57                 'label'            =>    'Area',
58                 'title'            =>    'Area',
59                 'description'    =>    'Choose the area to access here.',
60                 'values'        =>    array(
61                     array(
62                         'label'    =>    'Please choose an area...',
63                         'value'    =>    '',
64                     ),
65                     array(
66                         'label'    =>    'Very pretty area',
67                         'value'    =>    'a01',
68                     ),
69                     array(
70                         'label'    =>    'No-nonsense area',
71                         'value'    =>    'a02',
72                     ),
73                 ),
74             ),
75         ),
76     );
77     
78     // create the form
79     $form    =&    patForms::createForm( $elementsDefinition, array( 'name' => 'myForm' ) );
80     
81     // create the needed renderer
82     $renderer    =&    patForms::createRenderer( "Array" );
83     
84     // set the renderer
85     $form->setRenderer( $renderer );
86     
87     // use auto-validation
88     $form->setAutoValidate( 'save' );
89
90     // serialize the elements
91     $elements    =    $form->renderForm();
92     
93     
94     // ERROR DISPLAY ------------------------------------------------------
95     // ask the form if it has been submitted and display errors. For
96     // convenience and also to keep the examples easy to understand, all
97     // the following examples will use teh helper methods of the examples
98     // framework to display the errors and the form.
99     if( $form->isSubmitted() )
100     {
101         displayErrors( $form ); // see patExampleGen/customFunctions.php
102     }
103
104     // DISPLAY FORM ------------------------------------------------------
105     displayForm( $form, $elements ); // see patExampleGen/customFunctions.php
106
107
108     
109     
110     // EXAMPLE END ------------------------------------------------------
111     $exampleGen->displayFooter();
112 ?>
Note: See TracBrowser for help on using the browser.