Login Retreive lost passwordRegister
Search

Manual  /  Functions  /  Database Functions  /  dbTextSelectField

(Since version FH3 v1.2.6)

dbTextSelectField
dbTextSelectField (
string $title
string $name
string $table
string $field
string $extraSQL = null,
mixed $validator = null,
mixed $extra = null 
)

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
$field String the field which is retrieved from the table and put into the select part of this textfield.
$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.
$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:

With this field you have the possibility to present a user a selection from a table in your database to put in the textfield or type there own value

Example

<?php 

// include the formhandler 
include( 'FH3/class.dbFormHandler.php' ); 

// create new db formhandler object 
$oForm = new dbFormHandler(); 

// set the database info (create a new connection) 
$oForm -> dbInfo( 'database', 'table', 'mysql' ); 
$oForm -> dbConnect( 'localhost', 'username', 'password'); 

// new TextSelectfield 
$oForm -> dbTextSelectField( 
  'Options from a table', 
  'saveInField', 
  'loadFromTable', 
  array( 'keyField', 'valueField' ), 
  ' ORDER BY `valueField`', 
  FH_NOT_EMPTY 
); 

// button to submit 
$oForm -> submitButton(); 

// what to do when the form is saved 
$oForm -> onSaved( 'FH_RUN' ); 

// show the form 
$oForm -> flush(); 

// the function which is called when the data is saved 
function FH_RUN( $iID, $aData ) 
{ 
    echo "Your type or selected value '". $aData['saveInField'] ."' is saved!"; 
} 

?>

Latest change: 23 October 08 / 16:19

Comments

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