root/trunk/examples/example_api_locale_custom.php

Revision 179, 2.2 kB (checked in by schst, 4 years ago)

fix comment

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1 <?php
2 /**
3  * Example that shows how to set a locale or error messages
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         'username' => array(
38             'type' => 'String',
39             'attributes' => array(
40                 'required'        =>    'yes',
41                 'display'        =>    'yes',
42                 'edit'            =>    'yes',
43                 'label'            =>    'Nickname',
44                 'description'    =>    'Enter your nickname here.',
45                 'maxlength'        =>    '5',
46                 'minlength'        =>    '4',
47                 'default'        =>    'The Argh',
48                 'title'            =>    'Username',
49             ),
50         ),
51     );
52     
53     echo 'Setting locale to gungan (gu), which are read from a file... validation errors ';
54     echo 'will be displayed in gungan.<br/><br/>';
55     
56     // Set the locale to the custom locale 'gungan'.
57     patForms::setLocale( 'gu', 'locales/gungan.ini' );
58
59     // create our form
60     $form =& patForms::createForm( $elementsDefinition );
61
62     $rule = &patForms::createRule('Enum', 'myRule');
63     $rule->setValues(array('schst', 'argh', 'gerd'));
64     
65     $el = &$form->getElementByName('username');
66     $el->addRule($rule);
67     
68     // tell the form it has been submitted
69     $form->setSubmitted( true );
70
71     // validate the element - this will always fail here on purpose to show
72     // the error message
73     $form->validateForm();
74     
75     // display the errors
76     displayErrors( $form ); // see patExampleGen/customFunctions.php
77
78     $form->setValues(array('username' => 'Fooo'));
79     
80     // validate the element - this will always fail here on purpose to show
81     // the error message
82     $form->validateForm(true);
83     
84     // display the errors
85     displayErrors( $form ); // see patExampleGen/customFunctions.php
86     
87     
88     
89     // EXAMPLE END ------------------------------------------------------
90     $exampleGen->displayFooter();
91 ?>
92
Note: See TracBrowser for help on using the browser.