|
|
|
|
|
|
dbSelectField |
dbSelectField (
string |
$title |
string |
$name |
string |
$table |
mixed |
$fields |
string |
$extraSQL = null, |
mixed |
$validator = null, |
boolean |
$multiple = null, |
integer |
$size = null, |
mixed |
$extra = null, |
array |
$mergeArray = array() |
) |
Arguments:
Name |
Description |
$title |
Title of the field |
$name |
Name of the field |
$table |
The table where the values of this field should be fetched from |
$fields |
String or array with the field(s) which are retrieved from the table and put into the select field. |
$extraSQL |
Some extra SQL which will be included right achter the "FROM <table>" statement. With this you can order the items, join tables, etc. |
$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. |
$multiple |
Should it be possible to select more then one option? Default false. |
$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. |
$mergeArray |
The options off the database are merged with the options in this array. The optinos in $mergeArray will come first. |
Description:
With this function you can populate a selectfield with values which are loaded from a table.
Example
<?php
// include the formhandler
include( 'FH3/class.dbFormHandler.php' );
// create new db formhandler object
$form = new dbFormHandler();
// set the database info (create a new connection)
$form -> dbInfo( 'database', 'table', 'mysql' );
$form -> dbConnect( 'localhost', 'username', 'password');
// new selectfield
$form -> dbSelectField(
'Options from a table',
'saveInField',
'loadFromTable',
array( 'keyField', 'valueField' ),
' ORDER BY `valueField`',
FH_NOT_EMPTY
);
// button to submit
$form -> submitButton();
// what to do when the form is saved
$form -> onSaved( 'doRun' );
// show the form
$form -> flush();
// the function which is called when the data is saved
function doRun( $id, $data )
{
echo "Your selected value '". $data['saveInField'] ."' is saved!";
}
?>
|
See also: SelectField
Latest change: 21 March 06 / 21:38
Comments
John Doe |
21 November 10 / 20:41 |
|
This method parameters do not correspond to the given example. I assume a simple flaw in documenting? |
|
|
|
|