System:Form

From Aspen Documentation

Learn how to use these functions together to validate forms.

See an example of using these functions together to process a form in our Blog Tutorial.

The Form class was designed to make handling html forms easier. It's not meant for generating form fields, but rather processing data and associated database records. A few of these functions were used in the tutorial, but there's more available.

This class is available through form and is loaded by default.

Function Description
addError Adds a new error which will set error() to return true.
addField Adds a custom field name to the form handler with a default and/or current value.
addFields Adds an array of fields. Simply passes each item in the array to addField.
cv Returns the current value of a single field.
error Returns whether or not an error was set during validation.
getCurrentValue Returns the current value of a single field.
getDefaultValue Returns the default value of a single field.
getErrors Returns an array of all error messages.
isSubmitted Detects if a form is submitted by looking for an array of POST or GET. If using GET, you must state that via the argument.
loadRecord Loads a database table schema for use with the form and model class, as well as default values of an existing record, identified by a unique id.
loadTable Loads a database table schema for use with the form and model class.
printErrors Prints out any errors using the form_error_wrapping_html configuration as wrapping html.
resetDefaults Resets all fields to their default values. This will eliminate any POST/GET values for the fields and return the array to it's original state.
save This method activates either the insert or update database action. If called without a record id as an argument it will perform an insert. If called with an id, it will perform an update.
setCurrentValue Sets the current value of a field (may be different from both default and POST)
setDefaultValue Sets the default value of a field.


Field Validation Functions

Function Description
fieldsMatch Verifies that values of two field names match. Uses PHP == operator.
isAlnum Returns whether or not the field value is alphanumeric.
isAlpha Returns whether or not the field value is alpha only.
isCreditCard Validates that a string is a credit card number. Requires type parameter.
isCurrency Verifies that a string is valid currency.
isDate Verifies that a date is valid.
isEmail Verifies that an email address is valid.
isFilled Validates that the current value of a field is non-empty.
isFloat Returns whether or not the field value is a float.
isInt Returns whether or not the field value is an integer.
isIp Returns whether or not the field value is a valid IP address.
isPhoneNumber Verifies that a string is a valid phone number.