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 if (strtolower($this->method()) == 'post') {
95 $this->out->hidden('token-' . $this->id() ?: common_random_hexstr(3), common_session_token(), 'token');
102 * Sub-classes should overload this with the name of their form.
107 function formLegend()
112 * Visible or invisible data elements
114 * Display the form fields that make up the data of the form.
115 * Sub-classes should overload this to show their data.
125 * HTTP method used to submit the form
127 * Defaults to post. Subclasses can override if they need to.
129 * @return string the method to use for submitting
137 * Buttons for form actions
139 * Submit and cancel buttons (or whatever)
140 * Sub-classes should overload this to show their own buttons.
145 function formActions()
152 * Should be unique on the page. Sub-classes should overload this
153 * to show their own IDs.
155 * @return int ID of the form
164 * Action of the form.
166 * URL to post to. Should be overloaded by subclasses to give
167 * somewhere to post to.
169 * @return string URL to post to
177 * Class of the form. May include space-separated list of multiple classes.
179 * If 'ajax' is included, the form will automatically be submitted with
180 * an 'ajax=1' parameter added, and the resulting form or error message
181 * will replace the form after submission.
183 * It's up to you to make sure that the target action supports this!
185 * @return string the form's class
195 $this->out->elementStart('li');
200 $this->out->elementEnd('li');