CWIS Developer Documentation

- Home
- Main Page
- Namespaces
- Classes
- Files

- Class List
- Class Index
- Class Hierarchy
- Class Members

Public Member Functions | Static Public Member Functions | Public Attributes | List of all members
FormTool Class Reference

Helps print and validate form fields, and their errors, associated with a form. More...

## Public Member Functions
| FormTool ($FormFields, $AdditionalErrorMessages=NULL)
| Object constructor. More...
| ValueForField ($FieldName, $NewValue=NULL)
| Get and set the value for a form field. More...
| AllRequiredVarsAreSet ()
| Determine whether all of the required form field values are set in the POST variables. More...
| GetValsAsUrlParams ($IncludePasswords=FALSE)
| Return the URL parameter string with form field values that are set in the POST variables. More...
| SetFieldValuesFromUrlParams ()
| Set the values for the form fields from the URL parameters when available. More...
| IncomingFieldValuesHaveErrors ()
| Check the incoming form values for each field and report whether errors were found. More...
| GetErrorCodesAsUrlParams ()
| Return the URL parameter string with error codes for any form value errors. More...
| SetAdditionalErrorFields ($FieldNames)
| Save additional fields marked as having errors. More...
| SetAdditionalErrorCodes ($Codes)
| Save additional error codes if not already present. More...
| GetUrlWithValuesAndErrorCodes ($BaseUrl, $IncludePasswords=FALSE)
| Convenience method that adds value and error codes to the URL. More...
| GetErrorMessages ($EliminateDuplicateMessages=TRUE)
| Get the list of error messages based on the error codes from the URL via $_GET. More...
| PrintField ($FieldName)
| Print the label and input for given form field. More...
| PrintLabelForField ($FieldName)
| Print the label element for the given field. More...
| PrintInputForField ($FieldName)
| Print the input element for the given field. More...
| ErrorCodesAvailable ()
| Determine if there are any error codes available from the form. More...
| CheckFieldValue ($FieldName)
| Extracts a form variable for the specified field and validates it via the form objects. More...

## Static Public Member Functions
static | GetArrayOfUsStates ()
| Get an array of US state names with their two-letter abbreviations as the index. More...

## Public Attributes
| $Fields
| $ErrorColor
| $AdditionalErrorCodes
| $AdditionalErrorFields
| $AdditionalErrorMessages

## Detailed Description

Helps print and validate form fields, and their errors, associated with a form.

Definition at line 14 of file FormTool.php.

## Member Function Documentation

FormTool::AllRequiredVarsAreSet | ( |  | ) |

Determine whether all of the required form field values are set in the POST variables.

Returns
  Returns TRUE if all the required form field values are set in the POST variables.

Definition at line 100 of file FormTool.php.

FormTool::CheckFieldValue | ( |  | $FieldName | ) |

Extracts a form variable for the specified field and validates it via the form objects.

Parameters

  string | $FieldName | Form field name.

Returns
  Returns an error code.

Definition at line 510 of file FormTool.php.

Referenced by GetErrorCodesAsUrlParams(), PrintField(), PrintInputForField(), and PrintLabelForField().

Here is the caller graph for this function:

FormTool::ErrorCodesAvailable | ( |  | ) |

Determine if there are any error codes available from the form.

Returns
  Return TRUE if there are any error codes available.

Definition at line 426 of file FormTool.php.

Referenced by PrintField(), PrintInputForField(), and PrintLabelForField().

Here is the caller graph for this function:

FormTool::FormTool | ( |  | $FormFields,
|  |  | $AdditionalErrorMessages = `NULL`
| ) |  |

Object constructor.

Parameters

  mixed | $FormFields | Array of form field objects or the path to a file that loads and returns form field objects via `$FormFields`.
  array | $AdditionalErrorMessages | Additional error messages to add, if any. This parameter is optional.

Definition at line 25 of file FormTool.php.

References $AdditionalErrorMessages.

static FormTool::GetArrayOfUsStates | ( |  | ) |
| static

Get an array of US state names with their two-letter abbreviations as the index.

Returns
  Returns an array of US state names with their two-letter abbreviations as the index.

Definition at line 437 of file FormTool.php.

FormTool::GetErrorCodesAsUrlParams | ( |  | ) |

Return the URL parameter string with error codes for any form value errors.

The URL parameter string does not include a leading separator (? or &).

Returns
  Returns the URL parameter string with error codes or an empty string if no errors were found.

Definition at line 187 of file FormTool.php.

References CheckFieldValue().

Referenced by GetUrlWithValuesAndErrorCodes(), and IncomingFieldValuesHaveErrors().

Here is the caller graph for this function:

FormTool::GetErrorMessages | ( |  | $EliminateDuplicateMessages = `TRUE` | ) |

Get the list of error messages based on the error codes from the URL via $_GET.

Parameters

  bool | $EliminateDuplicateMessages | TRUE to remove error messages that are exactly the same.

Returns
  Returns an array of error messages.

Definition at line 318 of file FormTool.php.

FormTool::GetUrlWithValuesAndErrorCodes | ( |  | $BaseUrl,
|  |  | $IncludePasswords = `FALSE`
| ) |  |

Convenience method that adds value and error codes to the URL.

Parameters

  string | $BaseUrl | Base URL to which to add the value and error codes.
  bool | $IncludePasswords | TRUE to include password fields in the URL parameters.

Returns
  Returns the base URL with the values and error codes added to it.

Definition at line 300 of file FormTool.php.

References GetErrorCodesAsUrlParams(), and GetValsAsUrlParams().

FormTool::GetValsAsUrlParams | ( |  | $IncludePasswords = `FALSE` | ) |

Return the URL parameter string with form field values that are set in the POST variables.

The URL parameter string does not include a leading separator (? or &).

Parameters

  bool | $IncludePasswords | TRUE to include password fields in the URL parameters.

Definition at line 128 of file FormTool.php.

Referenced by GetUrlWithValuesAndErrorCodes().

Here is the caller graph for this function:

FormTool::IncomingFieldValuesHaveErrors | ( |  | ) |

Check the incoming form values for each field and report whether errors were found.

Returns
  Returns TRUE if errors were found.

Definition at line 174 of file FormTool.php.

References GetErrorCodesAsUrlParams().

FormTool::PrintField | ( |  | $FieldName | ) |

Print the label and input for given form field.

Parameters

  string | $FieldName | Form field name.

Definition at line 393 of file FormTool.php.

References CheckFieldValue(), and ErrorCodesAvailable().

FormTool::PrintInputForField | ( |  | $FieldName | ) |

Print the input element for the given field.

Parameters

  string | $FieldName | Form field name.

Definition at line 415 of file FormTool.php.

References CheckFieldValue(), and ErrorCodesAvailable().

FormTool::PrintLabelForField | ( |  | $FieldName | ) |

Print the label element for the given field.

Parameters

  string | $FieldName | Form field name.

Definition at line 404 of file FormTool.php.

References CheckFieldValue(), and ErrorCodesAvailable().

FormTool::SetAdditionalErrorCodes | ( |  | $Codes | ) |

Save additional error codes if not already present.

Parameters

  array | $Codes | Additional error codes to save.

Definition at line 274 of file FormTool.php.

FormTool::SetAdditionalErrorFields | ( |  | $FieldNames | ) |

Save additional fields marked as having errors.

Parameters

  array | $FieldNames | Field names to mark as having errors.

Definition at line 252 of file FormTool.php.

FormTool::SetFieldValuesFromUrlParams | ( |  | ) |

Set the values for the form fields from the URL parameters when available.

Definition at line 155 of file FormTool.php.

FormTool::ValueForField | ( |  | $FieldName,
|  |  | $NewValue = `NULL`
| ) |  |

Get and set the value for a form field.

Parameters

  string | $FieldName | Form field name.
  mixed | $NewValue | New value to set for the form field. This parameter is optional.

Returns
  mixed Returns The current value for the form field.

Definition at line 89 of file FormTool.php.

## Member Data Documentation

FormTool::$AdditionalErrorCodes

Definition at line 500 of file FormTool.php.

FormTool::$AdditionalErrorFields

Definition at line 501 of file FormTool.php.

FormTool::$AdditionalErrorMessages

Definition at line 502 of file FormTool.php.

Referenced by FormTool().

FormTool::$ErrorColor

Definition at line 499 of file FormTool.php.

FormTool::$Fields

Definition at line 498 of file FormTool.php.

The documentation for this class was generated from the following file:

- objects/FormTool.php