root/tags/RELEASE_0_9_0B1/examples/example_datasrc_countries.php

Revision 278, 3.0 kB (checked in by schst, 3 years ago)

Use a RadioGroup? and an Enum element in the example.

Line 
1 <?php
2 /**
3  * Example for the the countries datasource
4  *
5  * $Id: example_datasrc_object.php 117 2004-08-26 13:08:37Z argh $
6  *
7  * @access        public
8  * @package        patForms
9  * @subpackage    Examples
10  * @author        Stephan Schmidt <schst@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         'country' => array(
38             'type' => 'Enum',
39             'attributes' => array(
40                 'required'        =>    'yes',
41                 'display'        =>    'yes',
42                 'edit'            =>    'yes',
43                 'label'            =>    'Area',
44                 'title'            =>    'Area',
45                 'style'            =>    'width:200px;',
46                 'description'    =>    'Choose your country',
47                 'values'        =>    array(),
48             ),
49         ),
50         'country2' => array(
51             'type' => 'RadioGroup',
52             'attributes' => array(
53                 'required'        =>    'yes',
54                 'display'        =>    'yes',
55                 'edit'            =>    'yes',
56                 'label'            =>    'Area',
57                 'title'            =>    'Area',
58                 'style'            =>    'width:200px;',
59                 'description'    =>    'Choose your country',
60                 'values'        =>    array(),
61             ),
62         ),
63     );
64     
65     // create the form
66     $form    =&    patForms::createForm($elementsDefinition, array('name' => 'myForm'));
67
68     // set the form locale, the country selection is adjusted automatically
69     $form->setLocale('de');
70     
71
72     $countries = &patForms::createDatasource('Countries');   
73
74     // get the element
75     $el =& $form->getElementByName('country');
76     
77     // tell the element to use the datasource object
78     $el->setDataSource($countries);
79
80     // get the element
81     $el2 =& $form->getElementByName('country2');
82     
83     // tell the element to use the datasource object
84     $el2->setDataSource($countries);
85     
86     // PROCESS FORM ------------------------------------------------------
87
88     // create the needed renderer
89     $renderer    =&    patForms::createRenderer( "Array" );
90     
91     // set the renderer
92     $form->setRenderer( $renderer );
93     
94     // use auto-validation
95     $form->setAutoValidate( 'save' );
96
97     // serialize the elements
98     $elements    =    $form->renderForm();
99     
100     
101     // ERROR DISPLAY ------------------------------------------------------
102     // ask the form if it has been submitted and display errors. For
103     // convenience and also to keep the examples easy to understand, all
104     // the following examples will use teh helper methods of the examples
105     // framework to display the errors and the form.
106     if( $form->isSubmitted() )
107     {
108         displayErrors( $form ); // see patExampleGen/customFunctions.php
109     }
110
111     // DISPLAY FORM ------------------------------------------------------
112     displayForm( $form, $elements ); // see patExampleGen/customFunctions.php
113
114
115     
116     
117     // EXAMPLE END ------------------------------------------------------
118     $exampleGen->displayFooter();
119 ?>
Note: See TracBrowser for help on using the browser.