Login Retreive lost passwordRegister
Search

Manual  /  Functions  /  Fields  /  ListField

ListField
ListField (
string $title
string $name
array $options
mixed $validator
boolean $useArrayKeyAsValue = null,
string $onTitle = "Selected",
string $offTitle = "Available",
integer $size = 4,
string $extra = null,
boolean $verticalMode = null 
)

Arguments:

Name Description
$title Title of the field
$name Name of the field
$options The options 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).
$onTitle The title which will be displayed above the field where the items are in which will be saved. By default this is "Selected" but is language depented.
$offTitle The title which will be displayed above the field where the items are displayed where the user can select from. By default this is "Available" but is language depented.
$size The number of items which are displayed (the height of the field)
$extra This can be extra information which will be included in the fields html tag. You can add for example some CSS or javascript.
$verticalMode indicates whether the two selectfields should be stacked horizontally or vertically.

Description:

This function generates a ListField ( two select fields where you can move values from one to another)

When you double click on the buttons < or > all items are moved to the other field. When you double click on an item it will be moved to the other side.

This function returns an array as value. When the value has to be saved into a database the values are comma seperated inserted (like: option1, option2, option3, etc..).

Example

<?php

// the values for the listfield
$values = array(
  
=> "PHP",
  
=> "MySQL database",
  
=> "Frontpage extensions",
  
=> "ASP",
  
=> "10 MB extra webspace",
  
=> "Webmail",
  
=> "Cronjobs"
);

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

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

// the listfield
$form->ListField("Products""products"$values);

// buttons beneath it
$form->SubmitButton("Save");

// set the 'commit after form' function
$form->OnCorrect("doRun");

// flush the form
$form->Flush();

// function to show the selected items
function doRun($data) {
    global 
$values;

    
$message "You have selected the following products:\n";

    foreach(
$data["products"] as $id) {
        
$message .= " - ".$values[$id]." \n";
    }

    return 
$message;
}

?>

Preview image

preview image

Latest change: 05 March 10 / 08:35

Comments

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