root/tags/RELEASE_0_9_0B1/examples/example_element_set.php

Revision 271, 2.9 kB (checked in by argh, 3 years ago)

Fixed bug #172: modified behavior of the setValue for the set element so that you may pass either a string for a single selected value, or an array with a list of selected entries; fixed bug #173 in patForms_Rule_URL: translated missing french strings.

  • 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         'wishlist' => array(
38             'type' => 'Set',
39             'attributes' => array(
40                 'required'        =>    'yes',
41                 'display'        =>    'yes',
42                 'edit'            =>    'yes',
43                 'label'            =>    'Wishlist',
44                 'title'            =>    'Wishlist',
45                 'description'    =>    'Pick your wishes in the list.',
46                 'size'            =>    'auto',
47                 'maxsize'        =>    'none',
48                 'max'            =>    '4',
49                 'min'            =>    '2',
50                 'values'        =>    array(
51                     array(
52                         'label'    =>    'More patForms elements',
53                         'value'    =>    'w1',
54                     ),
55                     array(
56                         'label'    =>    'Javascript validation',
57                         'value'    =>    'w2'
58                     ),
59                     array(
60                         'label'    =>    'More Jägerschnitzel',
61                         'value'    =>    'w3'
62                     ),
63                     array(
64                         'label'    =>    'Soft green mushroom soup on sundays',
65                         'value'    =>    'w4'
66                     ),
67                     array(
68                         'label'    =>    'A real axe for the Argh',
69                         'value'    =>    'w5'
70                     ),
71                     array(
72                         'label'    =>    'Roasted chicken on demand',
73                         'value'    =>    'w6'
74                     ),
75                     array(
76                         'label'    =>    'A tank',
77                         'value'    =>    'w7'
78                     ),
79                 ),
80             ),
81         ),
82     );
83     
84     // create the form
85     $form    =&    patForms::createForm( $elementsDefinition, array( 'name' => 'myForm' ) );
86     
87     // create the needed renderer
88     $renderer    =&    patForms::createRenderer( "Array" );
89     
90     // set the renderer
91     $form->setRenderer( $renderer );
92     
93     // use auto-validation
94     $form->setAutoValidate( 'save' );
95
96     $el =& $form->getElementByName( 'wishlist' );
97     
98     // you can set the selected value(s) either as an array or a single string:
99     //$el->setValue( 'w7' );
100     //$el->setValue( array( 'w1', 'w4' ) );
101     
102     // serialize the elements
103     $elements    =    $form->renderForm();
104     
105     
106     // ERROR DISPLAY ------------------------------------------------------
107     // ask the form if it has been submitted and display errors. For
108     // convenience and also to keep the examples easy to understand, all
109     // the following examples will use teh helper methods of the examples
110     // framework to display the errors and the form.
111     if( $form->isSubmitted() )
112     {
113         displayErrors( $form ); // see patExampleGen/customFunctions.php
114     }
115
116     // DISPLAY FORM ------------------------------------------------------
117     displayForm( $form, $elements ); // see patExampleGen/customFunctions.php
118
119
120     
121     
122     // EXAMPLE END ------------------------------------------------------
123     $exampleGen->displayFooter();
124 ?>
Note: See TracBrowser for help on using the browser.