|
Cookbook /
InputDefaultSummary: Demonstrates various ways to set the default values for form controls
Version:
Prerequisites:
Status:in-core
Maintainer:
Categories: Forms
<< | Input | >> This page demonstrates various ways to set the default values for form controls.
|
(:input default rating medium:) (:input radio rating none:) None (:input radio rating low:) Low (:input radio rating medium:) Medium (:input radio rating high:) High (:input radio rating extreme:) Extreme |
None Low Medium High Extreme |
Of course, (:input default ...:) works for any control, not just radio buttons:
(:input default color red:) (:input checkbox color white:) White (:input checkbox color green:) Green (:input checkbox color red:) Red (:input checkbox color blue:) Blue |
White Green Red Blue |
(:input default color red:) (:input select color white:) (:input select color green:) (:input select color red:) (:input select color blue:) |
|
The (:input default ...:) directive works with textareas, provided there are no line breaks in the value:
(:input form:) (:input default area "This is the value of a text area.":) (:input textarea area rows=2 cols=40:) (:input end:) |
but you can set multi-line defaults for textarea controls using the source= parameter and PTVs. See below.
(:input default request=1 :) The request=1 parameter will result in setting the defaults of the controls with any values from a previous form submission. Try setting the form below, press "Go", and notice how the form controls retain their values even after submit is pressed:
(:input form method=get:) (:input default request=1:) Colors: (:input checkbox red 1:) Red (:input checkbox blue 1:) Blue (:input checkbox green 1:) Green Extras: (:input radio extras yes:) Yes (:input radio extras no:) No Name: (:input text name:) Year: (:input select year 2006:) (:input select year 2007:) (:input select year 2008:) (:input submit:) (:input end:) |
The (:input default ...:) directive above is simply an easy way to use markup to set entries in $InputValues. However, the (:input default:) directive won't replace any value that already exists (thus a form submission will take priority over the markup defaults).
(:input default source=... :) The source=Group.PageName parameter can be used to set the defaults of controls from PageTextVariables (PTVs) on another page (the source page). For this set the names of the controls to be the PTV names, for instance (:input text name=$:Town :) to set the default from a PTV Town.
You can set a multi-line default value in a (:input textarea ..:) control from a PTV on a source page by setting (:input default source=SourcePageName :) with the source pagename and setting the textarea input control as name=$:PTV. The following example gets a PTV called 'Message' from page Test.MultipleLinePTV
(:input defaults source=Test.MultipleLinePTV:) (:input textarea name=$:Message cols=50 rows=6 :) |
|
From within a script, the $InputValues array can also be used to set default values for form controls. These can come from any source -- including from a previous POST or GET operation. For example to enable forms to retain previous input, after unsuccessful submissions, set in a local config file:
foreach ($_GET as $k=>$v) $InputValues[$k] = htmlspecialchars($v);
The Test.InputDefaults page has the $InputValues array enabled so you can see how it works.
This is a great start! But there needs to be a way to specify multiple values for groups of checkboxes and select-multiple drop-down menus. Suggested syntax:
(:input default favorites PmWiki,PHP,Apache:)
Ben Stallings January 22, 2007, at 09:25 AM
It is necessary to put the default form before the non-default form entries it refers to.
BenoitDutilleul April 2, 2007, at 23:54 AM
It is also necessary to put a line break after the default tag.
Ben Stallings June 09, 2007, at 05:49 PM