]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - lib/form.php
Form class, superclass for form widgets
[quix0rs-gnu-social.git] / lib / form.php
1 <?php
2 /**
3  * Laconica, the distributed open-source microblogging tool
4  *
5  * Base class for forms
6  *
7  * PHP version 5
8  *
9  * LICENCE: This program is free software: you can redistribute it and/or modify
10  * it under the terms of the GNU Affero General Public License as published by
11  * the Free Software Foundation, either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU Affero General Public License for more details.
18  *
19  * You should have received a copy of the GNU Affero General Public License
20  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
21  *
22  * @category  Widget
23  * @package   Laconica
24  * @author    Evan Prodromou <evan@controlyourself.ca>
25  * @author    Sarven Capadisli <csarven@controlyourself.ca>
26  * @copyright 2009 Control Yourself, Inc.
27  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
28  * @link      http://laconi.ca/
29  */
30
31 if (!defined('LACONICA')) {
32     exit(1);
33 }
34
35 require_once INSTALLDIR.'/lib/widget.php';
36
37 /**
38  * Base class for forms
39  *
40  * We have a lot of common forms (subscribe, fave, delete) and this superclass
41  * lets us abstract out the basic features of the form.
42  *
43  * @category Widget
44  * @package  Laconica
45  * @author   Evan Prodromou <evan@controlyourself.ca>
46  * @author   Sarven Capadisli <csarven@controlyourself.ca>
47  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
48  * @link     http://laconi.ca/
49  *
50  * @see      HTMLOutputter
51  */
52
53 class Form extends Widget
54 {
55     /**
56      * Show the form
57      *
58      * Uses a recipe to output the form.
59      *
60      * @return void
61      * @see Widget::show()
62      */
63
64     function show()
65     {
66         $this->out->elementStart('form',
67                                  array('id' => $this->id(),
68                                        'method' => 'POST',
69                                        'action' => $this->action()));
70         $this->sessionToken();
71         $this->formData();
72         $this->formActions();
73         $this->out->elementEnd('form');
74     }
75
76     /**
77      * Include a session token for CSRF protection
78      *
79      * @return void
80      */
81
82     function sessionToken()
83     {
84         $this->out->hidden('token', common_session_token());
85     }
86
87     /**
88      * Visible or invisible data elements
89      *
90      * Display the form fields that make up the data of the form.
91      * Sub-classes should overload this to show their data.
92      *
93      * @return void
94      */
95
96     function formData()
97     {
98     }
99
100     /**
101      * Buttons for form actions
102      *
103      * Submit and cancel buttons (or whatever)
104      * Sub-classes should overload this to show their own buttons.
105      *
106      * @return void
107      */
108
109     function formActions()
110     {
111     }
112
113     /**
114      * ID of the form
115      *
116      * Should be unique on the page. Sub-classes should overload this
117      * to show their own IDs.
118      *
119      * @return int ID of the form
120      */
121
122     function id()
123     {
124         return null;
125     }
126
127     /**
128      * Action of the form.
129      *
130      * URL to post to. Should be overloaded by subclasses to give
131      * somewhere to post to.
132      *
133      * @return string URL to post to
134      */
135
136     function action()
137     {
138     }
139 }