root/trunk/examples/example_attributefilter_applyform.php

Revision 349, 3.5 kB (checked in by gerd, 3 years ago)

Draft of new feature: attribute filter

  • Property svn:keywords set to "Id"
Line 
1 <?php
2 /**
3  * Example
4  *
5  * $Id$
6  *
7  * @package     patForms
8  * @subpackage  Examples
9  * @author      gERD Schaufelberger <gerd@php-tools.net>
10  * @license     LGPL, see license.txt for details
11  * @link        http://www.php-tools.net
12  */
13
14    /**
15     * Main examples prepend file, needed *only* for the examples framework!
16     */
17     include_once 'patExampleGen/prepend.php';
18     $exampleGen->displayHead( 'Example' );
19
20
21     // EXAMPLE START ------------------------------------------------------
22
23    /**
24     * main patForms class
25     */
26     require_once $neededFiles['patForms'];
27
28    /**
29     * patErrorManager class
30     */
31     require_once $neededFiles['patErrorManager'];
32
33     // element definitions for this example
34     $elementsDefinition = array(
35         'temperature' => array(
36             'type' => 'Number',
37             'attributes' => array(
38                 'required'      =>  'yes',
39                 'display'       =>  'yes',
40                 'edit'          =>  'yes',
41                 'label'         =>  'Temperature',
42                 'title'         =>  'Temperature',
43                 'default'       =>  13,
44                 'min'           =>  -50,
45                 'max'           =>  50,
46                 'description'   =>  'Temperature in degree Celsius',
47             ),
48         ),
49         'windforce' => array(
50             'type' => 'Number',
51             'attributes' => array(
52                 'required'      =>  'yes',
53                 'display'       =>  'yes',
54                 'edit'          =>  'yes',
55                 'label'         =>  'Wind Force',
56                 'title'         =>  'Wind Force',
57                 'default'       =>  1,
58                 'min'           =>  0,
59                 'max'           =>  10,
60                 'description'   =>  'Wind force in beauford',
61             ),
62         ),
63         'winddirection' => array(
64             'type' => 'String',
65             'attributes' => array(
66                 'required'      =>  'yes',
67                 'display'       =>  'yes',
68                 'edit'          =>  'yes',
69                 'label'         =>  'Wind Direction',
70                 'title'         =>  'Wind Direction',
71                 'default'       =>  'Nord',
72                 'description'   =>  'Where does the wind come from?',
73             ),
74         ),
75     );
76
77     // create the form
78     $form   =&  patForms::createForm( $elementsDefinition, array( 'name' => 'myForm' ) );
79
80     // create the needed renderer
81     $renderer   =&  patForms::createRenderer( "Array" );
82
83     // set the renderer
84     $form->setRenderer( $renderer );
85
86     // use auto-validation
87     $form->setAutoValidate( 'save' );
88
89     // create the test filter
90     $filter =& patForms::createAttributeFilter( 'Test' );
91
92     // apply filter to all form elements
93     $form->applyAttributeFilter( $filter );
94
95     // serialize the elements
96     $elements   =   $form->renderForm();
97
98
99     // ERROR DISPLAY ------------------------------------------------------
100     // ask the form if it has been submitted and display errors. For
101     // convenience and also to keep the examples easy to understand, all
102     // the following examples will use teh helper methods of the examples
103     // framework to display the errors and the form.
104     if( $form->isSubmitted() )
105     {
106         displayErrors( $form ); // see patExampleGen/customFunctions.php
107     }
108
109     // DISPLAY FORM ------------------------------------------------------
110     displayForm( $form, $elements ); // see patExampleGen/customFunctions.php
111
112     // EXAMPLE END ------------------------------------------------------
113     $exampleGen->displayFooter();
114 ?>
Note: See TracBrowser for help on using the browser.