Class Form

Description

The Form class creates and processes HTML forms.

The Form class is a wrapper of sorts to create HTML forms based on the database schema and process them once submitted.

The Form class is a good example of a user defined Module.

Depends on:

  • View : Generate the HTML code
  • Sql : Set or update the database
  • Database, Table : Need to know the schema

Located in /phpfw.php (line 708)


	
			
Variable Summary
string $ajax_element
array $css_class
array $data
array $links
array $link_ids
array $tables
array $table_ids
Method Summary
Form Form ()
void add_css_class (string $element, string $class_name)
void add_link (mixed $table_name, mixed $table_id)
void add_table (mixed $table_name, [mixed $table_id = 0])
void ajaxify (string $ajax_element)
bool check_date (string $date_str)
void check_duplicate_table (string $table_name)
bool check_time (string $time_str)
string convert_date (string $date_str, [bool $year_first = false])
void create_form (string $name, string $module, string $action, [string $params = 0], [string $onsubmit = "javascript: return form.validate(this);"], [bool $show_name = true])
string get_data ()
void process_form ()
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])
Variables
string $ajax_element (line 763)
  • var: Form post will be performed using AJAX and the returned output will be added to this element (default: "")
array $css_class (line 758)
  • var:

    Associative array of CSS class names

    This array is used by the View::create_form() function to specify the CSS class names of the different form elements.

    E.g. $css_class['table'] = 'class_name';

    Element classes that can be modified:

    • table
    • tr
    • td
    • input
    • textarea
    • select

array $data (line 720)
  • var:

    The resulting form data array

    $data is an associative array and is used as the input for View::table_two_column_associative() called in the create_form() function.

    Format: $data("Left Column" => "Right Column") where

    • Left Column = Data field header
    • Right Column = Form element HTML code

array $links (line 735)
  • var: Array of table objects to load in this form
array $link_ids (line 740)
  • var: Array of table IDs if an update form
array $tables (line 725)
  • var: Array of table objects to load in this form
array $table_ids (line 730)
  • var: Array of table IDs if an update form
Methods
Constructor Form (line 770)

Constructor for the Form class

Zero initializes members.

Form Form ()
add_css_class (line 905)

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_link (line 850)

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_table (line 804)

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 (line 914)

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_date (line 1410)

Check if an mm-dd-yyyy formatted date is valid

  • return: Returns true if valid else false
bool check_date (string $date_str)
  • string $date_str: The date string to validate
check_duplicate_table (line 887)

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_time (line 1433)

Check that time entered is hh:mm value

  • return: Returns true if valid else false
bool check_time (string $time_str)
  • string $time_str: The time string to validate
convert_date (line 1383)

This function converts a date of format yyyy-mm-dd to mm-dd-yyyy and vice versa

  • return: Returns the resulting date string
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_form (line 928)

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&param=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_data (line 785)

Get the form data

  • return: The form data is returned
string get_data ()
process_form (line 1211)

Process a submitted form.

void process_form ()
update_form (line 1191)

Create a form to update a table row and all its linked rows

  • return: The resultant HTML code
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&param=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)

Documentation generated on Sat, 23 Jun 2007 21:28:26 -0500 by phpDocumentor 1.3.2