|
|
|
|
|
|
CheckBox |
CheckBox (
string |
$title |
string |
$name |
mixed |
$value |
mixed |
$validator = null, |
boolean |
$useArrayKeyAsValue |
string |
$extra = null, |
string |
$mask = null |
) |
Arguments:
Name |
Description |
$title |
Title of the field |
$name |
Name of the field |
$value |
The value which is used for the field. When you give an array multiple checkboxes will be generated. The array value is used for the field label. The array key is used as field value, but can be changed with the argument $useArrayKeyAsValue.
If a string is passed it will be used as value (No label is used!). |
$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). |
$extra |
This can be extra information which will be included in the fields html tag. You can add for example some CSS or javascript. |
$mask |
With this argument you can position the field(s). In the given mask a the placeholder %field% will be replaced with the field. When the mask is full and there are still fields, the mask will be repeated. This works the same as SetMask.
When no mask is given the mask will be used which is set in the config file in the var FH_DEFAULT_GLUE_MASK. |
Description:
This function generates one ore more CheckBoxes.
When an array of options is given, an array of the selected items will be returned.
Example
<?php
// include the class
include('FH3/class.FormHandler.php');
// the options for the checkbox
$animals = array(
"Dog",
"Cat",
"Cow"
);
// make a new $form object
$form = new FormHandler();
// make the checkbox
$form -> checkBox("Favorite animal(s)", "animal", $animals, null, false);
// 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 which handles the code after the form
function doRun($data)
{
// do something here
echo "Your favorite animal(s):\n ";
foreach($data['animal'] as $animal)
{
echo " - $animal\n";
}
}
?>
|
Example use which just one checkbox:
<?php
// include the class
include('FH3/class.FormHandler.php');
// make a new $form object
$form = new FormHandler();
// make the checkbox
$form -> checkBox("Ok?", "ok", 1);
// 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 which handles the code after the form
function doRun($data)
{
// do something here
if( $data['ok'] )
{
echo "Yeah!";
}
else
{
echo "Booo!";
}
}
?>
|
In this example the field will return 1 when it's checked. When it's not checked, the value will be "" (an empty string)
Because 1 is evaluated as true and "" as false this is easy to use for if statements...
Preview image
Latest change: 05 March 10 / 08:33
Comments
|
|
|
|