HTML_QuickForm_advmultiselect : The Definitive Guide |
We will start by creating a very simple form. Our goals are :
Copy the following code to a file, give it a .php extension, and display it in your browser:
Loading this file in your browser will simply show something like this screenshot.
Lets review this example step by step :
At the beginning we creates a HTML_QuickForm object that will contain the objects representing elements and all the other necessary information. We only pass the form's name to the constructor, which means that default values will be used for other parameters.
Our form will consist of three elements:
The first one is not the "real"
element, it is just a heading to improve presentation. The second
one is our advmultiselect element. Note that parameters for
HTML_QuickForm::addElement()
method have different meanings for different elements. That is so
because they are actually passed to these elements' constructors.
The $fruit_array
variable sets the
default values (code, label) for the fruit advmultiselect element.
It's time to define the fruit element attributes:
To put headers on each list (wherever you want: at top, or bottom), you need first to set these values. Then second, defines the placeholder in the template (as any other multi-label element).
Important | |
---|---|
Placeholders {label_2},
{label_3} are used, in the same way, for
all
HTML_QuickForm renderers, and defines: unselected list
(label_2 ), and selected list
(label_3 ).
|
Last step to complete definition of a advmultiselect element is to set the add and remove buttons.
Here we gave names Add >>
and
<< Remove
, with a skin handled
by the inputCommand
CSS class.
Warning | |
---|---|
Placeholders {add}, {remove} must exists into the template. Without them you won't see the move buttons. |
User's input overrides default values of the fruit advmultiselect element.
Before to validate and process the form, the building form step need one more thing. Don't forget, that to manage swaps between both list, we need some javascript code. It's now time to include into our HTML stream/template.
Note | |
---|---|
By given the false value as
argument to the getElementJs() method, we have choosen
to build javascript code with its script tags. Default
behavior is to get only raw code without surrounding script
tags. May be usefull with template integration and existing
js code.
|
This is a simple display example. In your scripts you'll usually want to store the values somewhere or do whatever else. The HTML_QuickForm::process() method may be of interest here.
HTML_QuickForm_advmultiselect : The Definitive Guide | v 1.4.0 : 9 Juin 2007 |