|
|
|
|
|
|
SelectField |
SelectField (
string |
$title |
string |
$name |
array |
$options |
mixed |
$validator = null, |
boolean |
$useArrayKeyAsValue |
boolean |
$multiple = false, |
integer |
$size = null, |
string |
$extra = null |
) |
Arguments:
Name |
Description |
$title |
Title of the field |
$name |
Name of the field |
$options |
The options used for the field. It is possible to group certain options. This can be done by adding LABEL in the key of the array. Offcourse every key must have a unique name. See the example below. |
$validator |
This can either be the name of your own validation function or the constant name of a predefined validator function. For more information about validators see Validators.
It is also possible to use a method as a validation function. In this case you should pass an array where the first item is the object and the second item the name of the method. |
$useArrayKeyAsValue |
Should the key of the array be used as the value for the field? If not (false) the array value is used. The default option for this can be set in the config file (see FH_DEFUALT_USEARRAYKEY). |
$multiple |
Should it be possible to select more then one option? |
$size |
The number of items which should be shown. Default 1, but when $multiple is set to true the size will be 4. |
$extra |
This can be extra information which will be included in the fields html tag. You can add for example some CSS or javascript. |
Description:
This function generates a SelectField on the form.
Note: the possibility to group certan options with LABEL only works with Microsoft Internet Explorer 6, Mozilla, Netscape Navigator 6 + and Opera 7.
Note: when "multiple" is enabled FH will return an array as value (otherwise a string). When the value is saved into a database it will be comma seperated.
Example
<?php
// the options
$browsers = array(
"" => "-- Select --",
"__LABEL(IE)__" => "Microsoft Internet Explorer",
"msie3" => "Microsoft Internet Explorer 3",
"msie4" => "Microsoft Internet Explorer 4",
"msie5" => "Microsoft Internet Explorer 5",
"msie55" => "Microsoft Internet Explorer 5.5",
"msie6" => "Microsoft Internet Explorer 6",
"__LABEL(MO)__" => "Mozilla",
"moz1" => "Mozilla 1",
"__LABEL(NN)__" => "Netscape Navigator",
"nn3" => "Netscape Navigator 3",
"nn4" => "Netscape Navigator 4",
"nn6" => "Netscape Navigator 5",
"nn6" => "Netscape Navigator 6",
"nn7" => "Netscape Navigator 7",
"__LABEL(OP)__" => "Opera",
"op3" => "Opera 3",
"op35" => "Opera 3.5",
"op4" => "Opera 4",
"op5" => "Opera 5",
"op6" => "Opera 6",
"op7" => "Opera 7"
);
// include the class
include('FH3/class.FormHandler.php');
// create a new formhandler object
$form = new FormHandler();
// the field
$form -> selectField("Your browser", "browser", $browsers, FH_NOT_EMPTY, true);
// button beneath it
$form -> submitButton("Save");
// set the 'commit after form' function
$form -> onCorrect("doRun");
// send the form to the screen
$form -> flush();
// the function witch handles the code after the form
function doRun($data)
{
return "Your browser: ". $data["browser"];
}
?>
|
Preview image
See also: LinkSelectFields
Latest change: 05 March 10 / 08:33
Comments
|
|
|
|