Tag Archives: control type

set_ctrltype()

set_ctrltype(mixed $col, mixed $ctrltype, null $keyvalue_pair, bool $multiple) : $this

Set HTML control type of a specific field. Select and Textare control types are automatically determined by the database field char type based on its length. But you can set it otherwise.

Parameters

mixed $col
  • Database table column name
mixed $ctrltype
  • HTML control type.
  • Supported types:
    • text
    • textarea
    • select
    • checkbox
    • passwords
    • button
    • autocomplete
    • wysiwyg
null $keyvalue_pair
  • Key value pair or SQL SELECT(select control type only)
bool $multiple
  • Multiple select (select control type only)

Input Element Type

PHP Database Form supports common form input types including

  • text (default input type)
  • textarea
  • select
  • autocomplete
  • checkbox
  • password
  • email
  • radio
  • checkbox (single checkbox .e.g true | false)
  • checkboxlist
  • wysiwyg

“select”, “autocomplete”, “radio”, “checkboxlist” all have a third parameter that can be either a list of key value pairs delimited by semicolon “;”, or a SQL SELECT.

“checkbox” also has a third parameter but with only a single key value pair. The default input type is always “text”.

Hint: add “:;” (colon semicolon) to the front of the the key value pairs to add a blank option. Do not include a trailing semicolon.

$dbForm = new C_DatabaseForm("SELECT * FROM Employees", "EmployeeID", "Employees");
$dbForm -> set_label("EmployeeID", "Employee ID");
$dbForm -> set_label("LastName", "Last Name");
$dbForm -> set_label("FirstName", "First Name");
$dbForm -> set_label("BirthDay", "DOB");
$dbForm -> set_hide("Extension");
$dbForm -> set_hide("hireDate");
$dbForm -> set_placeholder('Title', 'official job title');
$dbForm -> add_group_header("EmployeeID", "Basic Info");
$dbForm -> add_group_header("Email", "Contact Info");
$dbForm -> add_tooltip("BirthDate", "Enter employee birth date"); // tooltip supports HTML as well
$dbForm -> set_readonly(array('EmployeeID, LastName'));
$dbForm -> set_ctrltype('Notes', 'wysiwyg');
$dbForm -> set_ctrltype("Country", "autocomplete", "SELECT Code, Name FROM Country");
$dbForm -> set_ctrltype("ReportsTo", "select", "SELECT EmployeeID, LastName FROM Employees");
$dbForm -> set_ctrltype('Email', 'email');
$dbForm -> set_ctrltype('Gender', 'radio', 'M:MMM;F:FFF;Y:YYY;Z:ZZZ');
$dbForm -> set_ctrltype('IsActive', 'checkbox', '1:0');  // single key value pair only
$dbForm -> set_ctrltype('Shift', 'checkboxlist', 'Regular:Regular;Gravy Yard:Gravy Yard');
$dbForm -> set_ctrltype('SSN', 'password');
$dbForm -> display();

Live demo