summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--_test/cases/inc/form_form.test.php4
-rw-r--r--inc/form.php50
-rw-r--r--inc/html.php20
-rw-r--r--inc/media.php6
4 files changed, 43 insertions, 37 deletions
diff --git a/_test/cases/inc/form_form.test.php b/_test/cases/inc/form_form.test.php
index f69349ece..c342496fa 100644
--- a/_test/cases/inc/form_form.test.php
+++ b/_test/cases/inc/form_form.test.php
@@ -6,7 +6,7 @@ require_once DOKU_INC.'inc/form.php';
class form_test extends UnitTestCase {
function _testform() {
- $form = new Doku_Form('dw__testform','/test');
+ $form = new Doku_Form(array('id' => 'dw__testform', 'action' => '/test'));
$form->startFieldset('Test');
$form->addHidden('summary', 'changes &c');
$form->addElement(form_makeTextField('t', 'v', 'Text', 'text__id', 'block'));
@@ -88,7 +88,7 @@ class form_test extends UnitTestCase {
}
function test_close_fieldset() {
- $form = new Doku_Form('dw__testform','/test');
+ $form = new Doku_Form(array('id' => 'dw__testform', 'action' => '/test'));
$form->startFieldset('Test');
$form->addHidden('summary', 'changes &c');
$form->addElement(form_makeTextField('t', 'v', 'Text', 'text__id', 'block'));
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));
diff --git a/inc/html.php b/inc/html.php
index 0b6d01d72..bda9c88e4 100644
--- a/inc/html.php
+++ b/inc/html.php
@@ -33,7 +33,7 @@ function html_wikilink($id,$name=null,$search=''){
function html_attbuild($attributes){
$ret = '';
foreach ( $attributes as $key => $value ) {
- $ret .= $key.'="'.formtext($value).'" ';
+ $ret .= $key.'="'.formText($value).'" ';
}
return trim($ret);
}
@@ -51,7 +51,7 @@ function html_login(){
print p_locale_xhtml('login');
print '<div class="centeralign">'.NL;
- $form = new Doku_Form('dw__login');
+ $form = new Doku_Form(array('id' => 'dw__login'));
$form->startFieldset($lang['btn_login']);
$form->addHidden('id', $ID);
$form->addHidden('do', 'login');
@@ -244,7 +244,7 @@ function html_draft(){
$text = cleanText(con($draft['prefix'],$draft['text'],$draft['suffix'],true));
print p_locale_xhtml('draft');
- $form = new Doku_Form('dw__editform');
+ $form = new Doku_Form(array('id' => 'dw__editform'));
$form->addHidden('id', $ID);
$form->addHidden('date', $draft['date']);
$form->addElement(form_makeWikiText($text, array('readonly'=>'readonly')));
@@ -422,7 +422,7 @@ function html_revisions($first=0){
print p_locale_xhtml('revisions');
- $form = new Doku_Form('page__revisions', wl($ID));
+ $form = new Doku_Form(array('id' => 'page__revisions'));
$form->addElement(form_makeOpenTag('ul'));
if($INFO['exists'] && $first==0){
if (isset($INFO['meta']) && isset($INFO['meta']['last_change']) && $INFO['meta']['last_change']['type']===DOKU_CHANGE_TYPE_MINOR_EDIT)
@@ -586,7 +586,7 @@ function html_recent($first=0){
if (getNS($ID) != '')
print '<div class="level1"><p>' . sprintf($lang['recent_global'], getNS($ID), wl('', 'do=recent')) . '</p></div>';
- $form = new Doku_Form('dw__recent', script(), 'get');
+ $form = new Doku_Form(array('id' => 'dw__recent', 'method' => 'GET'));
$form->addHidden('sectok', null);
$form->addHidden('do', 'recent');
$form->addHidden('id', $ID);
@@ -997,7 +997,7 @@ function html_conflict($text,$summary){
global $lang;
print p_locale_xhtml('conflict');
- $form = new Doku_Form('dw__editform');
+ $form = new Doku_Form(array('id' => 'dw__editform'));
$form->addHidden('id', $ID);
$form->addHidden('wikitext', $text);
$form->addHidden('summary', $summary);
@@ -1039,7 +1039,7 @@ function html_register(){
print p_locale_xhtml('register');
print '<div class="centeralign">'.NL;
- $form = new Doku_Form('dw__register', wl($ID));
+ $form = new Doku_Form(array('id' => 'dw__register'));
$form->startFieldset($lang['register']);
$form->addHidden('do', 'register');
$form->addHidden('save', '1');
@@ -1075,7 +1075,7 @@ function html_updateprofile(){
if (empty($_POST['fullname'])) $_POST['fullname'] = $INFO['userinfo']['name'];
if (empty($_POST['email'])) $_POST['email'] = $INFO['userinfo']['mail'];
print '<div class="centeralign">'.NL;
- $form = new Doku_Form('dw__register', wl($ID));
+ $form = new Doku_Form(array('id' => 'dw__register'));
$form->startFieldset($lang['profile']);
$form->addHidden('do', 'profile');
$form->addHidden('save', '1');
@@ -1192,7 +1192,7 @@ function html_edit($text=null,$include='edit'){ //FIXME: include needed?
<?php } ?>
</div>
<?php
- $form = new Doku_Form('dw__editform');
+ $form = new Doku_Form(array('id' => 'dw__editform'));
$form->addHidden('id', $ID);
$form->addHidden('rev', $REV);
$form->addHidden('date', $DATE);
@@ -1443,7 +1443,7 @@ function html_resendpwd() {
print p_locale_xhtml('resendpwd');
print '<div class="centeralign">'.NL;
- $form = new Doku_Form('dw__resendpwd', wl($ID));
+ $form = new Doku_Form(array('id' => 'dw__resendpwd'));
$form->startFieldset($lang['resendpwd']);
$form->addHidden('do', 'resendpwd');
$form->addHidden('save', '1');
diff --git a/inc/media.php b/inc/media.php
index c9b7cfc56..d8ca288c1 100644
--- a/inc/media.php
+++ b/inc/media.php
@@ -646,7 +646,9 @@ function media_uploadform($ns, $auth){
if($auth < AUTH_UPLOAD) return; //fixme print info on missing permissions?
// The default HTML upload form
- $form = new Doku_Form('dw__upload', DOKU_BASE.'lib/exe/mediamanager.php', false, 'multipart/form-data');
+ $form = new Doku_Form(array('id' => 'dw__upload',
+ 'action' => DOKU_BASE.'lib/exe/mediamanager.php',
+ 'enctype' => 'multipart/form-data'));
$form->addElement('<div class="upload">' . $lang['mediaupload'] . '</div>');
$form->addElement(formSecurityToken());
$form->addHidden('ns', hsc($ns));
@@ -711,7 +713,7 @@ function media_searchform($ns,$query=''){
global $lang;
// The default HTML search form
- $form = new Doku_Form('dw__mediasearch', DOKU_BASE.'lib/exe/mediamanager.php', false);
+ $form = new Doku_Form(array('id' => 'dw__mediasearch', 'action' => DOKU_BASE.'lib/exe/mediamanager.php'));
$form->addElement('<div class="upload">' . $lang['mediasearch'] . '</div>');
$form->addElement(formSecurityToken());
$form->addHidden('ns', $ns);