root/trunk/examples/example_attributefilter_test.php

Revision 349, 2.7 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         'username' => array(
36             'type' => 'String',
37             'attributes' => array(
38                 'required'        =>    'yes',
39                 'display'        =>    'yes',
40                 'edit'            =>    'yes',
41                 'label'            =>    'Username',
42                 'title'            =>    'Username',
43                 'default'        =>    '       String with spaces',
44                 'description'    =>    'Please enter your username here.',
45             ),
46         ),
47     );
48
49     // create the form
50     $form    =&    patForms::createForm( $elementsDefinition, array( 'name' => 'myForm' ) );
51
52     // create the needed renderer
53     $renderer    =&    patForms::createRenderer( "Array" );
54
55     // set the renderer
56     $form->setRenderer( $renderer );
57
58     // use auto-validation
59     $form->setAutoValidate( 'save' );
60
61     // create the test filter
62     $filter =& patForms::createAttributeFilter( 'Test' );
63
64     // get the element
65     $el =& $form->getElementByName( 'username' );
66
67     // apply the filter to the element
68     $el->applyAttributeFilter( $filter );
69     
70     // Why not apply the filter for a second time - just to play with it...
71     $el->applyAttributeFilter( $filter );
72
73     $el->setAttribute( 'description', 'This is the new description, altered by the attribute filter!' );
74
75     // serialize the elements
76     $elements    =    $form->renderForm();
77
78
79     // ERROR DISPLAY ------------------------------------------------------
80     // ask the form if it has been submitted and display errors. For
81     // convenience and also to keep the examples easy to understand, all
82     // the following examples will use teh helper methods of the examples
83     // framework to display the errors and the form.
84     if( $form->isSubmitted() )
85     {
86         displayErrors( $form ); // see patExampleGen/customFunctions.php
87     }
88
89     // DISPLAY FORM ------------------------------------------------------
90     displayForm( $form, $elements ); // see patExampleGen/customFunctions.php
91
92     // EXAMPLE END ------------------------------------------------------
93     $exampleGen->displayFooter();
94 ?>
Note: See TracBrowser for help on using the browser.