InputDefaults
This page demonstrates various ways to set the default values for form controls.
(:input default ... :)
The (:input default name value:)
markup allows an author to set the default value for any input control with the corresponding name. For example, the following markup sets the default value of the "rating" radio buttons to "medium":
(: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 |
$InputValues
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, this page has the following local customization enabled in local/Test.InputDefaults.php:
foreach ($_GET as $k=>$v) $InputValues[$k] = htmlspecialchars($v);
As a result, any values from a previous form submission are used to set the defaults of the controls. 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:) 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 defaults source=Cookbook.Fox:) (:input textarea name=$:Summary cols=50 rows=5 :) |
|