<< | Input | >>
This page demonstrates various ways to set the default values for form controls.
None Low Medium High Extreme
(:input default ...:) works for any control, not just radio buttons:
White Green Red Blue
(:input default ...:) directive works with textareas, provided there are no line breaks in the value:
But you can set multi-line defaults for textarea controls using the source= parameter and PTVs. See below. You can also set multi-line defaults for textareas using [=:
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 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).
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 multiple pages as sources:
(:input default source=Page1,Page2,Page3:)? In that case, the first existing page where the user has read permissions, will be used to populate the form fields.
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
"defaults" is a synonym of "default".
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.
See discussion at InputDefault-Talk