From f462c963b5bd388d4620ac14c4ec238ddd4c54e9 Mon Sep 17 00:00:00 2001 From: rurban Date: Thu, 25 Nov 2004 12:04:17 +0000 Subject: [PATCH] support extra submit[] and reste[] buttons to place it before. renamed radiobutton to radio git-svn-id: svn://svn.code.sf.net/p/phpwiki/code/trunk@4191 96ab9672-09ca-45d6-a79d-3d69d39ca109 --- lib/plugin/WikiFormRich.php | 118 +++++++++++++++++++----------------- 1 file changed, 63 insertions(+), 55 deletions(-) diff --git a/lib/plugin/WikiFormRich.php b/lib/plugin/WikiFormRich.php index 2ca866102..83190b971 100644 --- a/lib/plugin/WikiFormRich.php +++ b/lib/plugin/WikiFormRich.php @@ -1,5 +1,5 @@ false, // required argument 'method' => 'POST', // or GET - 'class' => false, + 'class' => 'wikiaction', 'buttontext' => false, // for the submit button. default: action 'cancel' => false, // boolean if the action supports cancel also 'nobr' => false, // "no break": linebreaks or not ); } + /* TODO: support better block alignment:
, tables, indent + */ function handle_plugin_args_cruft($argstr, $args) { - $allowed = array("editbox", "hidden", "checkbox", "radiobutton", "pulldown"); + $allowed = array("editbox", "hidden", "checkbox", "radiobutton"/*deprecated*/, + "radio", "pulldown", "submit", "reset"); // no editbox[] = array(...) allowed (space) $arg_array = preg_split("/\n/", $argstr); // for security we should check this better $arg = ''; for ($i = 0; $i < count($arg_array); $i++) { - if (preg_match("/^\s*(".join("|",$allowed).")\[\]\s+(.+)\s*$/", $arg_array[$i], $m)) { + //TODO: we require an name=value pair here, but submit may go without also. + if (preg_match("/^\s*(".join("|",$allowed).")\[\](.*)$/", $arg_array[$i], $m)) { $name = $m[1]; // one of the allowed input types $this->inputbox[][$name] = array(); $j = count($this->inputbox) - 1; - $curargs = $m[2]; + $curargs = trim($m[2]); // must match name=NAME and also value= while (preg_match("/^(\w+)=((?:\".*\")|(?:\w+)|(?:\"?\"?))\s*/", $curargs, $m)) { $attr = $m[1]; $value = $m[2]; $curargs = substr($curargs, strlen($m[0])); if (preg_match("/^\"(.*)\"$/", $value, $m)) $value = $m[1]; - if (in_array($name, array("pulldown","checkbox","radiobutton")) + if (in_array($name, array("pulldown","checkbox","radio","radiobutton")) and preg_match('/^$/', $value, $m)) // like pulldown[] name=test value= { @@ -134,7 +139,7 @@ extends WikiPlugin //trigger_error("not yet finished"); //eval('$this->inputbox[]["'.$m[1].'"]='.$m[2].';'); } else { - trigger_error(sprintf("Invalid argument %s ignored",htmlentities($arg_array[$i])), + trigger_error(sprintf("Invalid argument %s ignored", htmlentities($arg_array[$i])), E_USER_WARNING); } } @@ -148,22 +153,25 @@ extends WikiPlugin } $form = HTML::form(array('action' => $request->getPostURL(), 'method' => $method, - 'class' => 'wikiadmin', + 'class' => 'wikiaction', 'accept-charset' => $GLOBALS['charset']), HiddenInputs(array('action' => $action))); if ($nobr) $nbsp = HTML::Raw(' '); + $already_submit = 0; foreach ($this->inputbox as $inputbox) { foreach ($inputbox as $inputtype => $input) { + if ($inputtype == 'radiobutton') $inputtype='radio'; // convert from older versions + $input['type'] = $inputtype; + if ($inputtype != 'submit') { + if (empty($input['name'])) + return $this->error(fmt("A required argument '%s' is missing.", + $inputtype."[][name]")); + if (!isset($input['text'])) $input['text'] = gettext($input['name']); + $text = $input['text']; + unset($input['text']); + } switch($inputtype) { case 'checkbox': - $input['type'] = 'checkbox'; - if (empty($input['name'])) - return $this->error(fmt("A required argument '%s' is missing.", - "checkbox[][name]")); - if (!isset($input['text'])) - $input['text'] = gettext($input['name']); //."=".$input['value']; - $text = $input['text']; - unset($input['text']); if (empty($input['checked'])) { if ($request->getArg($input['name'])) $input['checked'] = 'checked'; @@ -198,14 +206,7 @@ extends WikiPlugin $form->pushContent(HTML::div(array('class' => $class), HTML::input($input), $text)); } break; - case 'radiobutton': - $input['type'] = 'radio'; - if (empty($input['name'])) - return $this->error(fmt("A required argument '%s' is missing.", - "radiobutton[][name]")); - if (!isset($input['text'])) $input['text'] = gettext($input['name']); - $text = $input['text']; - unset($input['text']); + case 'radio': if ($input['checked']) $input['checked'] = 'checked'; if (is_array($input['value'])) { $div = HTML::div(array('class' => $class)); @@ -236,28 +237,17 @@ extends WikiPlugin break; case 'editbox': $input['type'] = 'text'; - if (empty($input['name'])) - return $this->error(fmt("A required argument '%s' is missing.", - "editbox[][name]")); - if (!isset($input['text'])) $input['text'] = gettext($input['name']); - $text = $input['text']; if (empty($input['value']) and ($s = $request->getArg($input['name']))) $input['value'] = $s; - unset($input['text']); if ($nobr) $form->pushContent(HTML::input($input), $nbsp, $text, $nbsp); else $form->pushContent(HTML::div(array('class' => $class), HTML::input($input), $text)); break; case 'pulldown': - if (empty($input['name'])) - return $this->error(fmt("A required argument '%s' is missing.", - "pulldown[][name]")); - if (!isset($input['text'])) $input['text'] = gettext($input['name']); - $text = $input['text']; - unset($input['text']); $values = $input['value']; unset($input['value']); + unset($input['type']); $select = HTML::select($input); if (empty($values) and ($s = $request->getArg($input['name']))) { $select->pushContent(HTML::option(array('value'=> $s), $s)); @@ -277,36 +267,54 @@ extends WikiPlugin } $form->pushContent($text, $select); break; + case 'reset': case 'hidden': - $input['type'] = 'hidden'; - if (empty($input['name'])) - return $this->error(fmt("A required argument '%s' is missing.", - "hidden[][name]")); - unset($input['text']); $form->pushContent(HTML::input($input)); + break; + // change the order of inputs, by explicitly placing a submit button here. + case 'submit': + //$input['type'] = 'submit'; + if (empty($input['value'])) $input['value'] = $buttontext ? $buttontext : $action; + unset($input['text']); + if (empty($input['class'])) $input['class'] = $class; + if ($nobr) + $form->pushContent(HTML::input($input), $nbsp, $text, $nbsp); + else + $form->pushContent(HTML::div(array('class' => $class), HTML::input($input), $text)); + // unset the default submit button + $already_submit = 1; + break; } } } if ($request->getArg('start_debug')) - $form->pushContent(HTML::input(array('name' => 'start_debug', - 'value' => $request->getArg('start_debug'), - 'type' => 'hidden'))); + $form->pushContent(HTML::input + (array('name' => 'start_debug', + 'value' => $request->getArg('start_debug'), + 'type' => 'hidden'))); if (!USE_PATH_INFO) $form->pushContent(HiddenInputs(array('pagename' => $basepage))); - if (empty($buttontext)) $buttontext = $action; - $submit = Button('submit:', $buttontext, $class); - if ($cancel) { - $form->pushContent(HTML::span(array('class' => $class), - $submit, Button('submit:cancel', _("Cancel"), $class))); - } else { - $form->pushContent(HTML::span(array('class' => $class), - $submit)); + if (!$already_submit) { + if (empty($buttontext)) $buttontext = $action; + $submit = Button('submit:', $buttontext, $class); + if ($cancel) { + $form->pushContent(HTML::span + (array('class' => $class), + $submit, + Button('submit:cancel', _("Cancel"), $class))); + } else { + $form->pushContent(HTML::span(array('class' => $class), + $submit)); + } } return $form; } }; // $Log: not supported by cvs2svn $ +// Revision 1.12 2004/11/24 15:21:19 rurban +// docs +// // Revision 1.11 2004/11/24 15:19:57 rurban // allow whitespace in quoted text args // @@ -360,4 +368,4 @@ extends WikiPlugin // c-hanging-comment-ender-p: nil // indent-tabs-mode: nil // End: -?> +?> \ No newline at end of file -- 2.45.0