Constructor for the Form class
Zero initializes members.
Form
Form
()
Update CSS class names for the form to be generated by View::create_form()
void
add_css_class
(string $element, string $class_name)
-
string
$element: Type of HTML element
-
string
$class_name:
Name of the CSS class to set this element to
See array View::$css_class for the list of HTML elements considered
Add a table link which will be populated when the form is processed
All tables added using Form::add_table() will be linked to the tables added using Form::add_link() if the corresponding table1_table2 link table exists in the database.
Multiple tables can be added. Function expects the name of the table and optionally the ID of the row in this table.
E.g.
- Adding a single table and ID : add_link('table_name', 5);
- Adding multiple tables and IDs : add_link(array('table1', 'table2'), array(5, 2));
void
add_link
(mixed $table_name, mixed $table_id)
-
mixed
$table_name: Name of the table to add (either a string or array of strings to add multiple tables)
-
mixed
$table_id: ID of the row in this table to link the form table with (either int or array of ints to add multiple table IDs)
Add a table to be rendered in this form
Multiple tables can be added. Function expects the name of the table and optionally the ID of the row in this table.
E.g.
- Adding a single table : add_table('table_name');
- Adding a single table and ID : add_table('table_name', 5);
- Adding multiple tables : add_table(array('table1', 'table2'));
- Adding multiple tables and IDs : add_table(array('table1', 'table2'), array(5, 2));
void
add_table
(mixed $table_name, [mixed $table_id = 0])
-
mixed
$table_name: Name of the table to add (either a string or array of strings to add multiple tables)
-
mixed
$table_id: Optional ID of the row in this table to load the form with (either int or array of ints to add multiple table IDs)
AJAXify the form - submit is performed using AJAX and returned data is added to the element specified
void
ajaxify
(string $ajax_element)
-
string
$ajax_element: The returned output will be added to this element
Check if an mm-dd-yyyy formatted date is valid
bool
check_date
(string $date_str)
-
string
$date_str: The date string to validate
Check if added table is already present in $this->tables or $this->links
Internal function, do not use.
void
check_duplicate_table
(string $table_name)
-
string
$table_name: Name of the table to check
Check that time entered is hh:mm value
bool
check_time
(string $time_str)
-
string
$time_str: The time string to validate
This function converts a date of format yyyy-mm-dd to mm-dd-yyyy and vice versa
string
convert_date
(string $date_str, [bool $year_first = false])
-
string
$date_str: The input date
-
bool
$year_first: If true, convert to yyyy-mm-dd else convert to mm-dd-yyyy
Create the form based on the specified tables and table_ids.
void
create_form
(string $name, string $module, string $action, [string $params = 0], [string $onsubmit = "javascript: return form.validate(this);"], [bool $show_name = true])
-
string
$name: Name of the form
-
string
$module: Name of the module with action to process this form
-
string
$action: Name of the action in this module that will process this form
-
string
$params: Parameters required for this module:action combination in "param=value¶m=value" format. (default: 0)
-
string
$onsubmit: Javascript to execute on submit - can be used to check form validity. (default: uses form.validate() in form.js)
-
bool
$show_name: Set to false to not display the external name of a table. (Default: true)
Get the form data
string
get_data
()
Process a submitted form.
void
process_form
()
Create a form to update a table row and all its linked rows
string
update_form
(string $table_name, int $table_id, string $name, string $module, string $action, [string $params = 0], [string $onsubmit = "javascript: return form.validate(this);"], [bool $show_name = true])
-
string
$table_name: Name of the table
-
int
$table_id: ID of the row in question
-
string
$name: Name of the form
-
string
$module: Name of the module with action to process this form
-
string
$action: Name of the action in this module that will process this form
-
string
$params: Parameters required for this module:action combination in "param=value¶m=value" format. (default: 0)
-
string
$onsubmit: Javascript to execute on submit - can be used to check form validity. (default: uses form.validate() in form.js)
-
bool
$show_name: Set to false to not display the external name of a table. (Default: true)