Login Retreive lost passwordRegister
Search

Manual  /  Functions  /  Fields  /  RadioButton

RadioButton
RadioButton (
string $title
string $name
array $options
mixed $validator = null,
boolean $useArrayKeyAsValue
string $extra = null,
string $mask = null 
)

Arguments:

Name Description
$title Title of the field
$name Name of the field
$options The options used for the field
$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 a group of radiobuttons on the form.

Example

<?php

// the options for the radiobutton
$gender = array(
  
"m" => "Male",
  
"f" => "Female"
);

// include the class
include('FH3/class.FormHandler.php');

// create new formhandler object
$form = new FormHandler();

// make the radiobutton
$form -> radioButton("Gender""gender"$gender);

// 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
{
   
// show the selected gender
   
echo "Hello, you are a ";

   switch(
$data["gender"]) 
   {
     case 
"m":
       echo 
"boy.";
       break;
     case 
"f":
       echo 
"girl.";
       break;
     default:
       echo 
"shemale!! Whaaaaa...";
       break;
    }
}

?>


If you want to set a default selected option, you can use the function SetValue.

In the example above that sould be:
<?php

// default select the male option
$form->SetValue("gender""m");

?>

Preview image

preview image

Latest change: 05 March 10 / 08:34

Comments

powered by PHP-GLOBE   © 2004 - 2024 FormHandler. All rights reserved.   -   Open source license