summaryrefslogtreecommitdiff
path: root/inc/form.php
diff options
context:
space:
mode:
authorAdrian Lang <lang@cosmocode.de>2009-10-22 14:01:38 +0200
committerAdrian Lang <lang@cosmocode.de>2009-10-22 14:01:38 +0200
commite351c80d455c51c1c334588fc5e9ff63ad63c09e (patch)
tree2b939e021bb2354c98fc396aa2a719b11bcdbae7 /inc/form.php
parent093f74569e82c2df98831c6db0c611086095fafe (diff)
downloadrpg-e351c80d455c51c1c334588fc5e9ff63ad63c09e.tar.gz
rpg-e351c80d455c51c1c334588fc5e9ff63ad63c09e.tar.bz2
Make Doku_Form constructor more flexible
The Doku_Form constructor used to take up to four arguments setting specific parameters of the resulting form HTML element. Instead, a generic array is passed to the constructor specifying HTML parameters. darcs-hash:20091022120138-e4919-3a42baf8c12b15e6df20e1f28152a992e347859d.gz
Diffstat (limited to 'inc/form.php')
-rw-r--r--inc/form.php50
1 files changed, 27 insertions, 23 deletions
diff --git a/inc/form.php b/inc/form.php
index d12827447..e638af4bc 100644
--- a/inc/form.php
+++ b/inc/form.php
@@ -29,17 +29,8 @@ require_once(DOKU_INC.'inc/html.php');
*/
class Doku_Form {
- // Usually either DOKU_SCRIPT or wl($ID)
- var $action = '';
-
- // Most likely no need to change this
- var $method = 'post';
-
- // Change for special forms only
- var $enctype = '';
-
// Form id attribute
- var $id = '';
+ var $params = array();
// Draw a border around form fields.
// Adds <fieldset></fieldset> around the elements
@@ -54,18 +45,33 @@ class Doku_Form {
/**
* Constructor
*
- * Autoadds a security token
+ * Sets parameters and autoadds a security token. The old calling convention
+ * with up to four parameters is deprecated, instead the first parameter
+ * should be an array with parameters.
*
- * @param string $id ID attribute of the form.
- * @param string $action (optional) submit URL, defaults to DOKU_SCRIPT
- * @param string $method (optional) 'POST' or 'GET', default is post
+ * @param mixed $params Parameters for the HTML form element; Using the
+ * deprecated calling convention this is the ID
+ * attribute of the form
+ * @param string $action (optional, deprecated) submit URL, defaults to
+ * current page
+ * @param string $method (optional, deprecated) 'POST' or 'GET', default
+ * is POST
+ * @param string $enctype (optional, deprecated) Encoding type of the
+ * data
* @author Tom N Harris <tnharris@whoopdedo.org>
*/
- function Doku_Form($id, $action=false, $method=false, $enctype=false) {
- $this->id = $id;
- $this->action = ($action) ? $action : script();
- if ($method) $this->method = $method;
- if ($enctype) $this->enctype = $enctype;
+ function Doku_Form($params, $action=false, $method=false, $enctype=false) {
+ if(!is_array($params)) {
+ $this->params = array('id' => $params);
+ if ($action !== false) $this->params['action'] = $action;
+ if ($method !== false) $this->params['method'] = $method;
+ if ($enctype !== false) $this->params['enctype'] = $enctype;
+ } else {
+ $this->params = $params;
+ }
+ if (!isset($this->params['method'])) {
+ $this->params['method'] = 'POST';
+ }
$this->addHidden('sectok', getSecurityToken());
}
@@ -240,10 +246,8 @@ class Doku_Form {
*/
function printForm() {
global $lang;
- print '<form action="'.$this->action.'" method="'.$this->method.'" accept-charset="'.$lang['encoding'].'"';
- if (!empty($this->id)) print ' id="'.$this->id.'"';
- if (!empty($this->enctype)) print ' enctype="'.$this->enctype.'"';
- print '><div class="no">'.NL;
+ $this->params['accept-charset'] = $lang['encoding'];
+ print '<form ' . html_attbuild($this->params) . '><div class="no">' . NL;
if (!empty($this->_hidden)) {
foreach ($this->_hidden as $name=>$value)
print form_hidden(array('name'=>$name, 'value'=>$value));