3 * StatusNet, the distributed open-source microblogging tool
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.
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.
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/>.
24 * @author Evan Prodromou <evan@status.net>
25 * @author Sarven Capadisli <csarven@status.net>
26 * @copyright 2009 StatusNet, Inc.
27 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
28 * @link http://status.net/
31 if (!defined('STATUSNET') && !defined('LACONICA')) {
35 require_once INSTALLDIR.'/lib/widget.php';
38 * Base class for forms
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.
45 * @author Evan Prodromou <evan@status.net>
46 * @author Sarven Capadisli <csarven@status.net>
47 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
48 * @link http://status.net/
53 class Form extends Widget
60 * Uses a recipe to output the form.
68 $attributes = array('id' => $this->id(),
69 'class' => $this->formClass(),
70 'method' => $this->method(),
71 'action' => $this->action());
73 if (!empty($this->enctype)) {
74 $attributes['enctype'] = $this->enctype;
76 $this->out->elementStart('form', $attributes);
77 $this->out->elementStart('fieldset');
79 $this->sessionToken();
82 $this->out->elementEnd('fieldset');
83 $this->out->elementEnd('form');
87 * Include a session token for CSRF protection
92 function sessionToken()
94 $this->out->hidden('token', common_session_token());
100 * Sub-classes should overload this with the name of their form.
105 function formLegend()
110 * Visible or invisible data elements
112 * Display the form fields that make up the data of the form.
113 * Sub-classes should overload this to show their data.
123 * HTTP method used to submit the form
125 * Defaults to post. Subclasses can override if they need to.
127 * @return string the method to use for submitting
135 * Buttons for form actions
137 * Submit and cancel buttons (or whatever)
138 * Sub-classes should overload this to show their own buttons.
143 function formActions()
150 * Should be unique on the page. Sub-classes should overload this
151 * to show their own IDs.
153 * @return int ID of the form
162 * Action of the form.
164 * URL to post to. Should be overloaded by subclasses to give
165 * somewhere to post to.
167 * @return string URL to post to
177 * @return string the form's class
187 $this->out->elementStart('li');
192 $this->out->elementEnd('li');