Classes to easily build HTML forms, as well as "Control Panels" ("Dashboards") consisting of a table of such forms (each of which is referred to as a "pane")
2 classes:
controlPanel
A Control Panel (aka Dashboard) is defined as a table of forms
formBuilder
A class to build and return simple HTML forms, especially suited for "Control Panels" (table of forms)
DEPENDENCIES: None
public $paneTitleStyle; // If provided, it will be used for each pane (containing a form)
public $tdWrapOptions; // Options for the <td> element of each cell (containing a form)
public $nCols; // Number of columns in the table of forms. This attribute needs to be public, because in some cases
// (involving table cells spanning multiple rows) it must be modified during execution
public $tableOptions = "border='1'"; // Styling for the larger table
private $row = 1; // Current row in the construction of the Control Panel
private $col = 1; // Current column
private $CPhtml = ""; // HTML forming the Control Panel
function __construct($nCols) // CONSTRUCTOR
// Specify the number of columns in the table of forms
public function addForm($form)
// Add a form (an object of type "formBuilder") to the Control Panel being built
public function addGeneralPane($html)
// Add a general pane (HTML consisting of <td> element and its content) to the Control Panel being built
public function generateCP()
// Generate and return the Control Panel
public $title; // Optional title to display just before the <form> element
public $titleStyle = "font-weight:bold; color:brown; font-size:12px"; // Default style to be used for the title
public $formStyle; // CSS used on the form
public $handler; // URL of script that will handle the form
public $submitLabel = "Enter"; // Text to show on the Submit button
public $hiddenOptions; // Array of HTML attributes for an optional <hidden> control. E.g.
// array("name='group' value='vert'" ,
// "name='plugin' value='t'")
// If just 1 element, it may optionally be passed as a string instead
function __construct($title, $handlerScript, $method = "POST") { // CONSTRUCTOR
/* $title Optional title (header text) to display just before the <form> element
$handlerScript URL of script that will handle the form. Use NULL if employing a JS handler
$method; Method ("POST" or "GET") to be used by the form to invoke its handler script
*/
public function addJS_handler($func)
// Specify a JS handler function, invoked when the form's submit button is clicked;
// it will be the JS handler's responsibility, if desired, to submit the form with document.testform.submit()
// An object containing the form is passed as argument to the JS function; for example, the function can extract the value of a field as: formObject.someFieldName.value
// See https://www.javaworld.com/article/2077176/using-javascript-and-forms.html?page=2
public function addHeaderLine($labelString)
// Append a row with the specififed label and a blank control. This pair might be used as a header at the top of the form, or as a mid-form sub-header/separator text
public function addFooter($text)
// Insert the given text (possibly HTML) at the very bottom of the form, right after the Submit button
public function addBlankLine()
// Append a row with a blank label and a blank control
public function addControl_General($labelString, $controlHTML)
/* Append a row with the specififed label and a general control (its HTML text).
Example of a text-input control: "<input type='text' name='someName'>"
More specific methods in this class are provided for many common controls (such as text, pulldown menus, etc)
*/
public function addControlText($label, $controlName, $size = null)
// Append a row with the specififed label and a text control, optionally specifying the size of the text field
public function addControl_Text($label, $controlName, $parArray = false)
/* Append a row with the specified label, and a text-input control with the given name and parameters.
The optional parameters of the text-input control are specified using entries of the $parArray argument; allowed values:
"value"
"size"
"maxlength"
"id"
"onclick"
"onchange"
EXAMPLE: $parArray = array("size" => "3" , "maxlength" => 5, "value" => "123" , "onclick" => "myClickFunction()")
For now, a few JS events are handled on a case-by-case.
Later on, maybe turn them into an array such as "js" => array("onclick" => "myClickFunction()" , "onchange" => "myChangeFunction()")
OR maybe: "js" => "onclick='myClickFunction()' onchange='myChangeFunction()'"
*/
public function addControl_Checkbox($label, $controlName, $parArray = false)
/* Append a row with the specififed label, and a chebox control with the given name and parameters.
EXAMPLE: addControl_Checkbox("Gift wrapped?", "gift", array("checked" => true))
Optional parameters are specified using elements of the $parArray argument; allowed values:
"checked"
"onclick"
"onchange"
EXAMPLE: $parArray = array("size" => "3" , "maxlength" => 5, "value" => "123" , "onclick" => "myClickFunction()")
For now, a few JS events are handled on a case-by-case.
Later on, maybe turn them into an array such as "js" => array("onclick" => "myClickFunction()" , "onchange" => "myChangeFunction()")
OR maybe: "js" => "onclick='myClickFunction()' onchange='myChangeFunction()'"
*/
public function addControl_Password($label, $controlName, $parArray = false)
/* Append a row with the specififed label, and a password-input control.
Optional parameters are specified using elements of the $parArray argument; allowed values:
"size"
"maxlength"
"id"
"onclick"
"onchange"
EXAMPLE: $parArray = array("size" => "3" , "maxlength" => 5, "value" => "123" , "onclick" => "myClickFunction()")
TO-DO: maybe combine with addControl_Text() ?
For now, a few JS events are handled on a case-by-case.
Later on, maybe turn them into an array such as "js" => array("onclick" => "myClickFunction()" , "onchange" => "myChangeFunction()")
OR maybe: "js" => "onclick='myClickFunction()' onchange='myChangeFunction()'"
*/
public function addControl_PulldownMenu($label, $menuDataset, $controlName, $selectedInstructions = "[SELECT]", $optionsArray = false)
/* Append a row with the specififed label, and a pull-down menu.
ARGUMENTS:
$menuDataset Must be a traversable object; for example an array or something returned by an SQL select query; its entries may be single values or arrays.
If its entries are single values or arrays with 1 element, they are used for both the picked value and the shown value;
if they are arrays with 2+ elements, the 1st element is used for the picked value, and the 2nd one is used for the shown value.
$controlName A string representing an array. It MUST end in "[]"; for example, "someName[]"
$selectedInstructions Optional. If present (and not over-ridden, see below), the first entry of the menu shows the specified string and is selected; its picked value is blanl
$optionsArray Optional array.
Element "style", if present, sets a CSS style for the <select> tag
Element "selected", if present, specifies a value in the dataset that will selected. This will only occur if the specified value actually occurs in the dataset; if it occurs, it will override $selectedInstructions, if applicable
*/
public function addControl_Hidden($name, $value)
// Add a "hidden input" to the form, with the given name/value pair
{
$this->hiddenOptions[] = "name='$name' value='$value'";
}
public function generateHTML($submitLabel = "")
/* Create and return an HTML form (preceded by an optional title, specified at object-instantiation time.)
The optional argument, if present, conveniently allows specifying a label insude the form' SUBMIT button.
*/