FiForm (Class)

From FiFormsWiki

Jump to: navigation, search

Note: This technical article describes the PHP class FiForm. For information on how to create forms in XML (the recommended method in the FiForms Framework), see the Forms article.

class FiForm extends iContainer

The main class which generates a FiForm to view / edit data. This is the only class you need to include when you are developing with the FiForms API.

The FiForm object contains all other objects on the form in the inputs attribute array. This class also does the work of querying and updating the database. It has methods to automatically generate input boxes for fields in a MySQL database or to declare input boxes (iInputs) one at a time.

Contents

Example

Following is a simple FiForm definition which displays a form based on a table named addressbook from the database FiForms-sample :

<?php
 require_once("FiForms_FiForm.inc.php"); 
 $frm = new FiForm();
 $frm->dataDB = "FiForms-sample";
 $frm->dataTable = "addressbook";
 $frm->autoinputs();
 echo $frm->drawFormPage();
?>


Properties

$controlsOnTop show the form control links on top and on bottom
$currentRec Index of current record in MySQL dataset or special word "last" or "new". (0=first record,... last=last record, new=new record) Obtained from $_GET[currentRec]
$dataDB the name of the database to connect to
$dataQuery Query used to retreive data from MySQL table. If not given, set to "SELECT * FROM $dataTable;" NOTE: never include a WHERE, GROUP BY, or HAVING clause in dataQuery. Use the where property to set the WHERE clause
$dataServer the name or IP address of MySQL Server
$dataTable name of table where data comes from, and also the table to update. If $dataQuery not given, used to construct $dataQuery
$dataUser username to connect to MySQL
$formAction the page to load. If not given, use PHP_SELF
$formatStrSV format string when form in in sheetView mode
$isProcessed tests whether the processData function has been called in this instance
$keyArray String of html containing primary keys in hidden inputs. Used to identify the record when updated.
$maxRec Index of the last record in MySQL dataset
$name the name of the form in the HTML output. Default value (if unset) is FiFormData.
$noMoveOnInsert if true, return to inserted record after insert, rather than moving to a new record.
$noNavigation disables the navigation links on the form control
$orderBy field(s) to order the query by
$readOnly global readOnly; if TRUE, sets all $this->inputs[]->readOnly=TRUE
$recordLimit Maximum number of records returned by dataQuery
$sheetView Set to TRUE if form is in sheetView mode. Set to TRUE if $_GET[sheetView] == 'YES'
$showDelete show the delete function, even if navigation is disabled
$where WHERE clause of the query used to fetch data from database. Obtained from $_GET[where]. NOTE: do not include the WHERE keyword
$wrapper contains HTML code to "wrap" the form into a complete HTML page; an object of class genericHTML or one of its derivatives.Properties inherited from iContainer: $drawCaption $drawInput $formatStr $inputs Properties inherited from iInput: $caption $currentRec $dbField $error $errorMsg $formatStr $formatStrRO $otherTags $readOnly $section $value $valueToSave


Method Summary

FiForm

Constructs a new FiForm object

addIn

Add a new iInput to the form.

autoInputs

Automatically generate iInputs

drawForm

Calls processData() to run all necessary queries of the database server, then draws the form with all controls and returns the result as a string, which can be placed in the body of an HTML document.

drawFormPage

Same as drawForm(), but wrapped in HTML to make a complete page

eraseIn

Erase an iInput from the form, i.e., an unnecessary field generated by autoInputs().

makeConnection

Connect to the MySQL database and select the database.

processData

Connect to and query database, and perform any necessary operations to save data in POST variables.

renameIn

Change to caption of a field on a form.Methods inherited from iContainer: drawInput iContainer outputRow Methods inherited from iInput: checkRO drawInput getValueToSave hide iInput throwError

Method Detail

FiForm

Constructs a new FiForm object

Syntax: FiForm($name,$dataDB,$dataTable)

Parameters

$name - The name of the form in the HTML output

$dataDB - Name of the database to connect to

$dataTable - name of table where data comes from, and also the table to update.

Examples

Example

Construct FiForm by passing connection info to constructor.

<?php
 require_once("FiForms_FiForm.inc.php"); 
 $frm = new FiForm("FiFormData","FiForms-sample","addressbook");
 
 // Define all your input boxes...
 
 echo $frm->drawFormPage();
?>

Example

Construct FiForm with an empty constructor. (This is the preferred method, as it is more easily readable.)

<?php
 require_once("FiForms_FiForm.inc.php"); 
 $frm = new FiForm();
 $frm->dataDB = "FiForms-sample";
 $frm->dataTable = "addressbook";
 
 // Define all your input boxes...
 
 echo $frm->drawFormPage();
?>

Returns

N/A


addIn

Add a new iInput to the form.

Syntax:addIn($class,$args...)


Parameters

$class - Name of class to construct.

$args... - Remaining arguments to be passed to constructor.

Returns

N/A


autoInputs

Automatically generate iInputs

Syntax:autoInputs()

Returns

N/A


drawForm

Calls processData() to run all necessary queries of the database server, then draws the form with all controls and returns the result as a string, which can be placed in the body of an HTML document.

Syntax:drawForm()


Returns

N/A

drawFormPage

Same as drawForm(), but wrapped in HTML to make a complete page

Syntax:drawFormPage()


Returns

N/A

eraseIn

Erase an iInput from the form, i.e., an unnecessary field generated by autoInputs().

Syntax:eraseIn($inputName)


Parameters

$inputName - Field Name (array key) of iInput to erase.

Returns

N/A

makeConnection

Connect to the MySQL database and select the database.

Syntax:makeConnection()

Returns

The connection ID returned by mysql_connect; FALSE on failure.

processData

Connect to and query database, and perform any necessary operations to save data in POST variables.

Syntax:processData()

Returns

N/A


renameIn

Change to caption of a field on a form.

Syntax:renameIn($inputName,$newName)


Parameters

$inputName - Field Name (array key) of iInput to rename.

$newName - New caption for field.

Returns

N/A

Personal tools