3 * Form action extendable class.
9 * @author Evan Prodromou <evan@status.net>
10 * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
11 * @link http://status.net/
13 * StatusNet - the distributed open-source microblogging tool
14 * Copyright (C) 2008, 2009, StatusNet, Inc.
16 * This program is free software: you can redistribute it and/or modify
17 * it under the terms of the GNU Affero General Public License as published by
18 * the Free Software Foundation, either version 3 of the License, or
19 * (at your option) any later version.
21 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU Affero General Public License for more details.
26 * You should have received a copy of the GNU Affero General Public License
27 * along with this program. If not, see <http://www.gnu.org/licenses/>.
30 if (!defined('GNUSOCIAL')) { exit(1); }
33 * Form action extendable class
37 * @author Evan Prodromou <evan@status.net>
38 * @author Mikael Nordfeldth <evan@status.net>
39 * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
40 * @link http://status.net/
42 class FormAction extends ManagedAction
44 protected $form = null;
45 protected $formOpts = array();
46 protected $type = null;
47 protected $needLogin = true;
48 protected $canPost = true;
50 protected function prepare(array $args=array()) {
51 parent::prepare($args);
53 $this->form = $this->form ?: ucfirst($this->action);
54 $this->args['form'] = $this->form;
56 $this->type = !is_null($this->type) ? $this->type : $this->trimmed('type');
57 $this->args['context'] = $this->trimmed('action'); // reply for notice for example
66 public function isReadOnly($args) {
67 return !$this->isPost();
70 public function showPageNotice()
72 $this->showInstructions();
73 if ($msg = $this->getError()) {
74 $this->element('div', 'error', $msg);
76 if ($msg = $this->getInfo()) {
77 $this->element('div', 'info', $msg);
82 * Outputs the instructions for the form
86 public function showInstructions()
88 // instructions are nice, so users know what to do
89 $this->raw(common_markup_to_html($this->getInstructions()));
93 * @return string with instructions to pass into common_markup_to_html()
95 protected function getInstructions()
100 public function showForm($msg=null, $success=false)
103 $this->success = $success;
107 protected function showContent()
109 $form = $this->getForm();
113 protected function getForm()
115 $class = $this->form.'Form';
116 $form = new $class($this, $this->formOpts);