FORMfields


FORMfields.FfForm

Class FfForm

FfForm

public class FfForm

FfForm encapsulates the form structure and functionality allowing one to easily perform form-wise functions, like writing to a database, and pass around the form structure and data in a single instance.

Since:
FORMfields v1.0

Field Summary
mixed

$error

True if an error in this form was detected.

mixed

$formErrors

An array of errors that are not particular to an individual field.

mixed

$formFields

Stores the fields in this form in display order.

mixed

$formListeners

Callback classes that processes certain form actions.

mixed

$formName

The value of the name attribute in the form tag.

mixed

$isError

True if an error in this form was detected.

mixed

$validators

Callback classes that process form validation.

Constructor Summary

FfForm()

The FfForm constructor.

__construct()

The FfForm constructor.

Method Summary
private string

__toString()

Returns HTML that displays this form's field values in a nicely formatted table.

void

addField(FormField formField, string afterFieldName)

Adds or inserts a field into this form's field list.

void

addFieldToFront(FormField formField)

Inserts a field at the front of the field list.

void

addFields(FfForm ffForm, string afterFieldName)

Adds all the fields from another form to this form.

void

addFormError(string error)

Adds a form error string to the end of the form error list.

void

addFormListener(mixed formListener)

Adds a form listener to this form, a callback class that processes certain form actions like assigning default field values.

void

addFormValidator(mixed formValidator)

Adds a form validator, callback classes that are used to implement form validation.

void

addSingleRow(string fieldName, TableSet table, string hiddenFields, string buttons)

Adds a row, appends a hidden field or appends a button for the specified field.

boolean

checkValues()

Performs field value validation for this form and using any form validators.

void

clearAllData()

Clears the values of all the fields in this form.

void

clearValue(string name)

Clears a field's value.

boolean

containsData()

Returns true if this form contains data.

void

copyAllFields(mixed ffForm, mixed afterFieldName)

Copies all fields from another form to this form.

void

copyFields(FfForm ffForm, array fieldsToCopy)

Copies fields from another form to this form, including any field data and field errors.

void

copyValues(FfForm ffForm)

Copies the field values from another form as long as the field name exists in this form.

array

diff(FfForm oldFfForm, array ignoreFieldNames)

Returns an associative array indexed by field name where each element is an array of {,}

void

disableField(FormField name)

Disables a field in this form.

void

email(string to, string subject, string from, string cc, string bcc, string msgHeader, string msgFooter, array attachments, mixed useHtml, string cssFile, boolean sendFormData, boolean sendFormUploads, useHtml false)

Sends an HTML or clear text email.

boolean

fieldExists(string fieldName)

Returns true if the field exists.

boolean

fieldsExist(array fieldNames)

Returns true if all the fields exist.

boolean

getButtonClicked()

Returns true if a submit button was clicked.

string

getDbValue(string name)

Returns the database value of a field in this form.

array

getDbValues(array fieldNames)

Returns an associative array of database values for fields in this form.

string

getDisableJs(array fieldNames, mixed exceptFieldNames, array exceptfieldNames)

Returns JavaScript code to disable all fields during run-time.

string

getDisplayTableTag(string classPostfix, boolean showDescriptions, mixed showFieldHelp, boolean displayHelp)

Returns the HTML to display this form in display mode.

string

getEmailMessage(string message, string msgHeader, string msgFooter, array attachments, mixed useHtml, string cssFile, boolean sendFormData, boolean sendFormUploads, useHtml false)

Returns the readable section of the email message.

boolean

getError()

Returns true if an error in the this form was detected

FormField

getField(string fieldName)

Returns a field from this form.

array

getFieldErrors()

Returns an array of form errors.

string

getFieldLabel(string fieldName)

Returns the field's label.

array

getFieldLabels(array fieldNames)

Returns an array of field labels.

string

getFieldName(string fieldLabel)

Returns the field's name.

array

getFieldNames(array fieldLabels)

Returns an array of field names.

string

getFieldTag(string name)

Returns the HTML that displays the input field.

string

getFormName()

Returns the value of the name attribute in the form tag.

string

getHiddenFieldTag(string name)

Returns the HTML that describes this field as a hidden field

string

getIfError()

Returns an error formatted in HTML if this form has any errors.

string

getLabelTag(string name)

Returns the HTML that displays the field label.

void

getParameters()

Retrieves the posted form values.

string

getRawMailMessage(string message, string additionalHeaders, array attachments, mixed useHtml, useHtml false)

Returns the raw multipart content of an email.

string

getSingleFieldTableTag(string name)

Returns the HTML to display a form with just a single field from this form.

string

getTableTag(string classPostfix)

Returns the HTML to display this form in editing mode.

mixed

getValue(string name)

Returns a field's value.

string

getValueIfExists(string name)

Returns the value of a field if it exists in this form.

array

getValues(array fieldNames)

Returns an associative array of values for fields in this form.

void

insertValuesIntoDb(string tableName, boolean ignoreError)

Inserts values in the specified table according to the database values of the fields in this form.

boolean

isBlank(string name)

Returns true if the field value is blank such as when the user hasn't filled in the value.

boolean

isEmpty(mixed fieldName, string name)

Returns true if the field value is blank such as when the user hasn't filled in the value.

void

keepFields(array fieldNames)

Removes all fields except those specified.

void

loadDbValues(array assocArray)

Loads database field values from an associative array where the index is the field name.

void

loadDbValuesNoCreate(array assocArray)

Loads database field values from an associative array where the index is the field name.

void

loadValuesFromDb(string tableName, string whereClause, boolean ignoreError)

Loads the database values of the fields in this form.

void

loadValuesFromQuery(string sql, boolean ignoreError)

Loads the database values of the fields in this form from a specified SQL query.

void

mail(string to, string subject, string message, string additionalHeaders, mixed additionalParameters, string from, string cc, string bcc, array attachments, mixed useHtml, string additionalParameter, useHtml false)

Sends an HTML or clear text email.

void

performActions()

Uses the form listener and any appropriate button listener to perform the form actions.

void

process()

Retrieves submitted form values and then uses the button listener, form listener and any appropriate button listener to perform the form actions.

void

removeAllEmptyFields(array exceptFieldNames)

Removes all empty fields.

void

removeField(string fieldName)

Removes a field from this form.

void

removeFields(array fieldNames)

Removes fields from this form

void

setDbValue(string name, string value)

Sets the database value of a field in this form.

void

setEditable(boolean editable)

Enable or disable editing of a field in this form.

void

setEditableFields(array fieldNames, boolean editable)

Enables or disables editing of fields in this form.

void

setEnabled(boolean enabled)

Enable or disable a field in this form.

void

setEnabledFields(array fieldNames, boolean enabled)

Enables or disables fields in this form.

void

setEnterTabs(boolean enterTabs)

Sets whether pressing enter on an input field submits the form or moves the focus to the next element.

void

setError(FormField name, string error)

Sets the error string for a field in this form.

void

setFormName(string formName)

Sets the value of the name attribute in the form tag.

void

setHelp(string fieldName, string help)

Sets the field help of a field in this form.

void

setHiddenFields(array fieldNames, boolean isHidden)

Hides or shows the specified fields.

void

setValue(string name, string value)

Sets the value of a field in this form.

string

toString()

Returns HTML that displays this form's field values in a nicely formatted table.

resource

trackedUpdate(string tableName, string whereClause, string userId, string primaryKey, array ignoreFieldNames, string attrChangesTableName, boolean ignoreError)

Uses the attribute changes construct in FfDbHelper to record the difference between the new data in this form and the old saved data in the database and then updates the data in the database with this form's new data.

void

updateValuesInDb(string tableName, string whereClause, boolean ignoreError)

Updates the values in the specified table according to the database values of the fields in this form.

boolean

validate()

Performs field value validation for this form.

Field Detail

error

public mixed $error = false

True if an error in this form was detected.

Since:
FORMfields v3.0

formErrors

public mixed $formErrors = array()

An array of errors that are not particular to an individual field.

Since:
FORMfields v3.0

formFields

public mixed $formFields = array()

Stores the fields in this form in display order.

Since:
FORMfields v1.0

formListeners

public mixed $formListeners = array()

Callback classes that processes certain form actions.

See Also:
FORMfields.FfFormListener
Since:
FORMfields v3.0

Constructor Detail

FfForm

public FfForm()

The FfForm constructor.

Since:
FORMfields v2.0
Deprecated:
deprecated as this constructor syntax is not expected in PHP 5 - will be removed once PHP 5 becomes a minimum requirement for FORMfields

__construct

public __construct()

The FfForm constructor.

Since:
FORMfields v2.0

Method Detail

__toString

private string __toString()

Returns HTML that displays this form's field values in a nicely formatted table. This function is primarily used for debugging.

Returns:
HTML that displays this form's field values in a nicely formatted table
Since:
FORMfields v3.0

addField

public void addField(FormField formField, string afterFieldName)

Adds or inserts a field into this form's field list.

Parameters:
formField - the form field to add
afterFieldName - if not null, the field is inserted after the field by this name, otherwise the field is added to the end of the field list
Since:
FORMfields v1.0

addFieldToFront

public void addFieldToFront(FormField formField)

Inserts a field at the front of the field list.

Parameters:
formField - the FormField to add
Since:
FORMfields v3.0

addFields

public void addFields(FfForm ffForm, string afterFieldName)

Adds all the fields from another form to this form.

Parameters:
ffForm - the form from which to add fields
afterFieldName - if not null, the fields are inserted after the field by this name in this form, otherwise the fields are added to the end of the field list
Since:
FORMfields v3.0

addFormError

public void addFormError(string error)

Adds a form error string to the end of the form error list. Note: you should only use this method to report form errors that are not specific to a field. You should use setError() to set errors for specific fields.

Parameters:
error - a form error string
Since:
FORMfields v3.0

addFormListener

public void addFormListener(mixed formListener)

Adds a form listener to this form, a callback class that processes certain form actions like assigning default field values.

See Also:
FORMfields.FfFormListener
Since:
FORMfields v3.0

FORMfields