A record form adds, updates or deletes data in a database record.

This class, adds several html-fields (text, selection box, ...) to a form, and the necessary buttons (Add, Update, Delete, Copy). It provides the logic for : - inserting a new record to a database - modifying data of an existing record - deleting an existing record - copying the values of an existing record, to a new form - validating the values of the fields

category Form
package Formaid
author Dieter Adriaenssens
copyright 2006-2013 Dieter Adriaenssens
license GPL
link http://formaid.sourceforge.net/

 Methods

Constructor, initialises an instance of Formaid_RecordForm

__construct(string $table_name, string $file_name, string $field_selectionname, string $orderby, string $return_url, string $database, string $idName) : void

Parameters

$table_name

string

Table name

$file_name

string

File name of page containing the table

$field_selectionname

string

Name of column to select on (caption)

$orderby

string

SQL column name to order by

$return_url

string

URL to return to after processing form

$database

string

Database to use

$idName

string

Name of ID field in database

Displays a HTML form.

display(string $mode) : void
Inherited
inherited_from \Formaid_Form::display()

Parameters

$mode

string

Mode this function is working in (form, value)

Display record values

displayValues() : void
Inherited

Execute display() method in "values" mode. In this mode, no form is displayed, but the values of the record are printed on the webpage. The values can't be edited.

inherited_from \Formaid_Form::displayValues()

Generates HTML code a record form on a web page.

getDisplayString(string $mode) : string

If the mode is form, a form is shown : this includes a title, form tags and form fields (input boxes, ...) If the mode is value, only the values of a record are shown, there is no possibility to change and submit values.

todo move generating of buttons to a seperate method, so that the parent function can be used, limiting the amount of duplicate code.

Parameters

$mode

string

Mode this function is working in (form, value)

Returns

string

Custom string that will be appended before automatically generated form

getDisplayStringPrefix(string $mode) : string

Parameters

$mode

string

Mode this function is working in (form, values)

Returns

string

Custom string that will be appended after automatically generated form

getDisplayStringSuffix(string $mode) : string

Parameters

$mode

string

Mode this function is working in (form, values)

Returns

string

Creates a link to the page to create a new record

getLinkCreateNew() : object

Returns

objectLink object pointing to modify record page

Creates a link to the page to modify a record

getLinkModify() : object

Returns

objectLink object pointing to modify record page

Checks if a submit request was made and executes it, without outputting a form.

prepareRun() : string

This function checks if a form was submitted and takes appropriate actions : - insert data in a database (add a new record) - update data in a database (modify an existing record) - remove data from a database (delete an existing record) - copy data in current form (creates a new form, omitting the record ID)

After validating the data in the form, the requested action is executed and the next action is returned : - show (a form can be displayed) - null (nothing can be displayed, a redirect is necessary)

Use prepareRun() and evaluate the output when you use a custom header and footer, or when you use custom output. Example : if ($form->prepareRun() == "show") { // output header

$form->display();

// output footer

}

Returns

stringnext action

Read values

readValues(int $ID) : void

Basically, this is an API to read data from a database record. If ID is specified, it will execute a SELECT query to retrieve a record, if the ID it is not specified, data is read from POST values.

access public

Parameters

$ID

int

record ID

Runs a form, executing a submit request and/or drawing a form.

run() : void

prepareRun() is called to check if there was a submit request and execute it. If prepareRun() returns next action "show", a form is displayed.

Example : $form->run();

see \prepareRun()

Displays a HTML form.

show(string $mode) : void
Inherited
inherited_from \Formaid_Form::show()

Parameters

$mode

string

Mode this function is working in (form, value)

Display record values

showValues() : void
Inherited

Execute display() method in "values" mode. In this mode, no form is displayed, but the values of the record are printed on the webpage. The values can't be edited.

inherited_from \Formaid_Form::showValues()

Updates data in database

updateDbValues() : void

Basically, this is an API to create/update data in a database record, without having to submit a form request. If ID is specified, it will update a record, if it is not specified, a new record will be created and the new ID will assigned to ID object.

access public

Validates the form values.

validate() : string

All record forms are validated, depending on the result, the next action is defined (run, display form, ...)

todo low : validate values

Returns

stringaction after validation

Checks if adding a new record is allowed.

allowAdd() : bool

If the Privilege on this record (allow_add) is set, it is allowed to add a new record.

Returns

booltrue if adding is allowed.

Checks if copying the record is allowed.

allowCopy() : bool

If the Privilege on this record (allow_copy) is set, it is allowed to copy the record.

Returns

booltrue if copying is allowed.

Checks if deleting the record is allowed.

allowDelete() : bool

If the Privilege on this record (allow_delete) is set, it is allowed to delete the record.

Returns

booltrue if deleting is allowed.

Checks if displaying the form is allowed.

allowShow() : bool
Inherited

If the Privilege on this form (allow_show) is set, it is allowed to display the form.

inherited_from \Formaid_Form::allowShow()

Returns

booltrue if displaying is allowed.

Checks if updating (editing) the record is allowed.

allowUpdate() : bool

If the Privilege on this record (allow_update) is set, it is allowed to update (edit) the record.

Returns

booltrue if updating is allowed.

Retrieve values from a database using an SELECT statement.

getSelectQueryResult() : array

Returns

arrayquery result

Post update action

postSubmitAction(string $submitType, string $message) : void

After an update (insert, update, delete) of a record, this method is executed.

access protected

Parameters

$submitType

string

Submittype : insert, update, delete

$message

string

Message for user to pass in the url

Redirect to a new url

redirectToUrl(string $message) : void

Usually this happens after an insert/modify or delete

Parameters

$message

string

Message for user to pass in the url

Deletes values stored in a database using a DELETE statement.

_deleteDbValues(bool $redirect) : string

Parameters

$redirect

bool

redirect HTML page after insert (default : true)

Returns

stringmessage

Insert values in a database using an INSERT statement.

_insertDbValues(bool $redirect) : string

Parameters

$redirect

bool

redirect HTML page after insert (default : true)

Returns

stringmessage

Updates values stored in a database using an UPDATE statement.

_updateDbvalues(bool $redirect) : string

Parameters

$redirect

bool

redirect HTML page after insert (default : true)

Returns

stringmessage

 Properties

 

$ID : object
access public
 

$data : array
Inherited
access public
inherited_from \Formaid_Form::$$data
 

$filename : string
Inherited
access public
inherited_from \Formaid_Form::$$filename
 

$form_select : object
access public
 

$message : string
Inherited
access public
inherited_from \Formaid_Form::$$message
   

$privileges : array
Inherited
access public
inherited_from \Formaid_Form::$$privileges
 

$return_url : string
Inherited
access public
inherited_from \Formaid_Form::$$return_url
 

$sql_table : string
Inherited
access public
inherited_from \Formaid_Form::$$sql_table
 

$title : string
Inherited
access public
inherited_from \Formaid_Form::$$title
 

$urlOverview : string
access public
 

$db_connection : object
Inherited
access protected
inherited_from \Formaid_Form::$$db_connection
 

$encoding : string
Inherited
access protected
inherited_from \Formaid_Form::$$encoding