root/trunk/examples/example_attributefilter_gettext.php

Revision 349, 2.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         'username' => array(
36             'type' => 'String',
37             'attributes' => array(
38                 'required'        =>    'yes',
39                 'display'        =>    'yes',
40                 'edit'            =>    'yes',
41                 'label'            =>    'gettext:\'Username\'',
42                 'title'            =>    'gettext:\'Username\'',
43                 'default'        =>    'superman',
44                 'description'    =>    'gettext:\'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( 'Gettext' );
63
64     // get the element
65     $el =& $form->getElementByName( 'username' );
66
67     // apply the filter to the element<br>
68     $el->applyAttributeFilter( $filter );
69
70     // serialize the elements
71     $elements    =    $form->renderForm();
72
73
74     // ERROR DISPLAY ------------------------------------------------------
75     // ask the form if it has been submitted and display errors. For
76     // convenience and also to keep the examples easy to understand, all
77     // the following examples will use teh helper methods of the examples
78     // framework to display the errors and the form.
79     if( $form->isSubmitted() )
80     {
81         displayErrors( $form ); // see patExampleGen/customFunctions.php
82     }
83
84     // DISPLAY FORM ------------------------------------------------------
85     displayForm( $form, $elements ); // see patExampleGen/customFunctions.php
86
87     // EXAMPLE END ------------------------------------------------------
88     $exampleGen->displayFooter();
89 ?>
Note: See TracBrowser for help on using the browser.