JForm
Form Class for the Joomla Platform.
This class implements a robust API for constructing, populating, filtering, and validating forms. It uses XML definitions to construct form fields and a variety of field and rule classes to render and validate the form.
package |
Joomla.Platform |
---|---|
subpackage |
Form |
link | |
since |
11.1 |
Methods
__construct
Method to instantiate the form object.
__construct(string $name, array $options = array())
since |
11.1 |
---|
Arguments
- $name
string
The name of the form.- $options
array
An array of form options.
addFieldPath
Proxy for {@link JFormHelper::addFieldPath()}.
addFieldPath(mixed $new = null) : array
since |
11.1 |
---|
Arguments
- $new
mixed
A path or array of paths to add.
Response
array
The list of paths that have been added.
addFormPath
Proxy for JFormHelper::addFormPath().
addFormPath(mixed $new = null) : array
see | \JFormHelper::addFormPath() |
---|---|
since |
11.1 |
Arguments
- $new
mixed
A path or array of paths to add.
Response
array
The list of paths that have been added.
addNode
Adds a new child SimpleXMLElement node to the source.
addNode(\SimpleXMLElement $source, \SimpleXMLElement $new) : void
since |
11.1 |
---|---|
throws |
|
Arguments
- $source
\SimpleXMLElement
The source element on which to append.- $new
\SimpleXMLElement
The new element to append.
addRulePath
Proxy for JFormHelper::addRulePath().
addRulePath(mixed $new = null) : array
see | \JFormHelper::addRulePath() |
---|---|
since |
11.1 |
Arguments
- $new
mixed
A path or array of paths to add.
Response
array
The list of paths that have been added.
bind
Method to bind data to the form.
bind(mixed $data) : boolean
since |
11.1 |
---|
Arguments
- $data
mixed
An array or object of data to bind to the form.
Response
boolean
True on success.
bindLevel
Method to bind data to the form for the group level.
bindLevel(string $group, mixed $data) : void
since |
11.1 |
---|
Arguments
- $group
string
The dot-separated form group path on which to bind the data.- $data
mixed
An array or object of data to bind to the form for the group level.
filter
Method to filter the form data.
filter(array $data, string $group = null) : mixed
since |
11.1 |
---|
Arguments
- $data
array
An array of field values to filter.- $group
string
The dot-separated form group path on which to filter the fields.
Response
mixed
Array or false.
filterField
Method to apply an input filter to a value based on field data.
filterField(string $element, mixed $value) : mixed
since |
11.1 |
---|
Arguments
- $element
string
The XML element object representation of the form field.- $value
mixed
The value to filter for the field.
Response
mixed
The filtered value.
findField
Method to get a form field represented as an XML element object.
findField(string $name, string $group = null) : mixed
since |
11.1 |
---|
Arguments
- $name
string
The name of the form field.- $group
string
The optional dot-separated form group path on which to find the field.
Response
mixed
The XML element object for the field or boolean false on error.
findFieldsByFieldset
Method to get an array of
findFieldsByFieldset(string $name) : mixed
since |
11.1 |
---|
Arguments
- $name
string
The name of the fieldset.
Response
mixed
Boolean false on error or array of SimpleXMLElement objects.
findFieldsByGroup
Method to get an array of
findFieldsByGroup(mixed $group = null, boolean $nested = false) : mixed
since |
11.1 |
---|
Arguments
- $group
mixed
The optional dot-separated form group path on which to find the fields. Null will return all fields. False will return fields not in a group.- $nested
boolean
True to also include fields in nested groups that are inside of the group for which to find fields.
Response
mixed
Boolean false on error or array of SimpleXMLElement objects.
findGroup
Method to get a form field group represented as an XML element object.
findGroup(string $group) : mixed
since |
11.1 |
---|
Arguments
- $group
string
The dot-separated form group path on which to find the group.
Response
mixed
An array of XML element objects for the group or boolean false on error.
getErrors
Return all errors, if any.
getErrors() : array
since |
11.1 |
---|
Response
array
Array of error messages or JException objects.
getField
Method to get a form field represented as a JFormField object.
getField(string $name, string $group = null, mixed $value = null) : mixed
since |
11.1 |
---|
Arguments
- $name
string
The name of the form field.- $group
string
The optional dot-separated form group path on which to find the field.- $value
mixed
The optional value to use as the default for the field.
Response
mixed
The JFormField object for the field or boolean false on error.
getFieldAttribute
Method to get an attribute value from a field XML element. If the attribute doesn't exist or is null then the optional default value will be used.
getFieldAttribute(string $name, string $attribute, mixed $default = null, string $group = null) : mixed
since |
11.1 |
---|
Arguments
- $name
string
The name of the form field for which to get the attribute value.- $attribute
string
The name of the attribute for which to get a value.- $default
mixed
The optional default value to use if no attribute value exists.- $group
string
The optional dot-separated form group path on which to find the field.
Response
mixed
The attribute value for the field.
getFieldset
Method to get an array of JFormField objects in a given fieldset by name. If no name is given then all fields are returned.
getFieldset(string $set = null) : array
since |
11.1 |
---|
Arguments
- $set
string
The optional name of the fieldset.
Response
array
The array of JFormField objects in the fieldset.
getFieldsets
Method to get an array of fieldset objects optionally filtered over a given field group.
getFieldsets(string $group = null) : array
since |
11.1 |
---|
Arguments
- $group
string
The dot-separated form group path on which to filter the fieldsets.
Response
array
The array of fieldset objects.
getFormControl
Method to get the form control. This string serves as a container for all form fields. For example, if there is a field named 'foo' and a field named 'bar' and the form control is empty the fields will be rendered like: and . If the form control is set to 'joomla' however, the fields would be rendered like: and .
getFormControl() : string
since |
11.1 |
---|
Response
string
The form control string.
getGroup
Method to get an array of JFormField objects in a given field group by name.
getGroup(string $group, boolean $nested = false) : array
since |
11.1 |
---|
Arguments
- $group
string
The dot-separated form group path for which to get the form fields.- $nested
boolean
True to also include fields in nested groups that are inside of the group for which to find fields.
Response
array
The array of JFormField objects in the field group.
getInput
Method to get a form field markup for the field input.
getInput(string $name, string $group = null, mixed $value = null) : string
since |
11.1 |
---|
Arguments
- $name
string
The name of the form field.- $group
string
The optional dot-separated form group path on which to find the field.- $value
mixed
The optional value to use as the default for the field.
Response
string
The form field markup.
getInstance
Method to get an instance of a form.
getInstance(string $name, string $data = null, array $options = array(), string $replace = true, string $xpath = false) : object
since |
11.1 |
---|---|
throws |
|
Arguments
- $name
string
The name of the form.- $data
string
The name of an XML file or string to load as the form definition.- $options
array
An array of form options.- $replace
string
Flag to toggle whether form fields should be replaced if a field already exists with the same group/name.- $xpath
string
An optional xpath to search for the fields.
Response
object
JForm instance.
getLabel
Method to get the label for a field input.
getLabel(string $name, string $group = null) : string
since |
11.1 |
---|
Arguments
- $name
string
The name of the form field.- $group
string
The optional dot-separated form group path on which to find the field.
Response
string
The form field label.
getName
Method to get the form name.
getName() : string
since |
11.1 |
---|
Response
string
The name of the form.
getValue
Method to get the value of a field.
getValue(string $name, string $group = null, mixed $default = null) : mixed
since |
11.1 |
---|
Arguments
- $name
string
The name of the field for which to get the value.- $group
string
The optional dot-separated form group path on which to get the value.- $default
mixed
The optional default value of the field value is empty.
Response
mixed
The value of the field or the default value if empty.
load
Method to load the form description from an XML string or object.
load(string $data, string $replace = true, string $xpath = false) : boolean
The replace option works per field. If a field being loaded already exists in the current form definition then the behavior or load will vary depending upon the replace flag. If it is set to true, then the existing field will be replaced in its exact location by the new field being loaded. If it is false, then the new field being loaded will be ignored and the method will move on to the next field to load.
since |
11.1 |
---|
Arguments
- $data
string
The name of an XML string or object.- $replace
string
Flag to toggle whether form fields should be replaced if a field already exists with the same group/name.- $xpath
string
An optional xpath to search for the fields.
Response
boolean
True on success, false otherwise.
loadField
Method to load, setup and return a JFormField object based on field data.
loadField(string $element, string $group = null, mixed $value = null) : mixed
since |
11.1 |
---|
Arguments
- $element
string
The XML element object representation of the form field.- $group
string
The optional dot-separated form group path on which to find the field.- $value
mixed
The optional value to use as the default for the field.
Response
mixed
The JFormField object for the field or boolean false on error.
loadFieldType
Proxy for {@link JFormHelper::loadFieldType()}.
loadFieldType(string $type, boolean $new = true) : mixed
since |
11.1 |
---|
Arguments
- $type
string
The field type.- $new
boolean
Flag to toggle whether we should get a new instance of the object.
Response
mixed
JFormField object on success, false otherwise.
loadFile
Method to load the form description from an XML file.
loadFile(string $file, string $reset = true, string $xpath = false) : boolean
The reset option works on a group basis. If the XML file references groups that have already been created they will be replaced with the fields in the new XML file unless the $reset parameter has been set to false.
since |
11.1 |
---|
Arguments
- $file
string
The filesystem path of an XML file.- $reset
string
Flag to toggle whether form fields should be replaced if a field already exists with the same group/name.- $xpath
string
An optional xpath to search for the fields.
Response
boolean
True on success, false otherwise.
loadRuleType
Proxy for JFormHelper::loadRuleType().
loadRuleType(string $type, boolean $new = true) : mixed
see | \JFormHelper::loadRuleType() |
---|---|
since |
11.1 |
Arguments
- $type
string
The rule type.- $new
boolean
Flag to toggle whether we should get a new instance of the object.
Response
mixed
JFormRule object on success, false otherwise.
mergeNode
Adds a new child SimpleXMLElement node to the source.
mergeNode(\SimpleXMLElement $source, \SimpleXMLElement $new) : void
since |
11.1 |
---|
Arguments
- $source
\SimpleXMLElement
The source element on which to append.- $new
\SimpleXMLElement
The new element to append.
mergeNodes
Merges new elements into a source
mergeNodes(\SimpleXMLElement $source, \SimpleXMLElement $new) : void
since |
11.1 |
---|
Arguments
- $source
\SimpleXMLElement
The source element.- $new
\SimpleXMLElement
The new element to merge.
removeField
Method to remove a field from the form definition.
removeField(string $name, string $group = null) : boolean
since |
11.1 |
---|
Arguments
- $name
string
The name of the form field for which remove.- $group
string
The optional dot-separated form group path on which to find the field.
Response
boolean
True on success.
removeGroup
Method to remove a group from the form definition.
removeGroup(string $group) : boolean
since |
11.1 |
---|
Arguments
- $group
string
The dot-separated form group path for the group to remove.
Response
boolean
True on success.
reset
Method to reset the form data store and optionally the form XML definition.
reset(boolean $xml = false) : boolean
since |
11.1 |
---|
Arguments
- $xml
boolean
True to also reset the XML form definition.
Response
boolean
True on success.
setField
Method to set a field XML element to the form definition. If the replace flag is set then the field will be set whether it already exists or not. If it isn't set, then the field will not be replaced if it already exists.
setField( &$element, string $group = null, boolean $replace = true) : boolean
since |
11.1 |
---|
Arguments
- $element
- $group
string
The optional dot-separated form group path on which to set the field.- $replace
boolean
True to replace an existing field if one already exists.
Response
boolean
True on success.
setFieldAttribute
Method to set an attribute value for a field XML element.
setFieldAttribute(string $name, string $attribute, mixed $value, string $group = null) : boolean
since |
11.1 |
---|
Arguments
- $name
string
The name of the form field for which to set the attribute value.- $attribute
string
The name of the attribute for which to set a value.- $value
mixed
The value to set for the attribute.- $group
string
The optional dot-separated form group path on which to find the field.
Response
boolean
True on success.
setFields
Method to set some field XML elements to the form definition. If the replace flag is set then the fields will be set whether they already exists or not. If it isn't set, then the fields will not be replaced if they already exist.
setFields( &$elements, string $group = null, boolean $replace = true) : boolean
since |
11.1 |
---|
Arguments
- $elements
- $group
string
The optional dot-separated form group path on which to set the fields.- $replace
boolean
True to replace existing fields if they already exist.
Response
boolean
True on success.
setValue
Method to set the value of a field. If the field does not exist in the form then the method will return false.
setValue(string $name, string $group = null, mixed $value = null) : boolean
since |
11.1 |
---|
Arguments
- $name
string
The name of the field for which to set the value.- $group
string
The optional dot-separated form group path on which to find the field.- $value
mixed
The value to set for the field.
Response
boolean
True on success.
syncPaths
Method to synchronize any field, form or rule paths contained in the XML document.
syncPaths() : boolean
since |
11.1 |
---|---|
todo |
Maybe we should receive all addXXXpaths attributes at once? |
Response
boolean
True on success.
validate
Method to validate form data.
validate(array $data, string $group = null) : mixed
Validation warnings will be pushed into JForm::errors and should be retrieved with JForm::getErrors() when validate returns boolean false.
since |
11.1 |
---|
Arguments
- $data
array
An array of field values to validate.- $group
string
The optional dot-separated form group path on which to filter the fields to be validated.
Response
mixed
True on sucess.
validateField
Method to validate a JFormField object based on field data.
validateField(string $element, string $group = null, mixed $value = null, object $input = null) : mixed
since |
11.1 |
---|
Arguments
- $element
string
The XML element object representation of the form field.- $group
string
The optional dot-separated form group path on which to find the field.- $value
mixed
The optional value to use as the default for the field.- $input
object
An optional JRegistry object with the entire data set to validate against the entire form.
Response
mixed
Boolean true if field value is valid, JException on failure.
Properties
data
The JRegistry data store for form fields during display.
since |
11.1 |
---|
Type(s)
object
errors
The form object errors array.
since |
11.1 |
---|
Type(s)
array
name
The name of the form instance.
since |
11.1 |
---|
Type(s)
string
options
The form object options for use in rendering and validation.
since |
11.1 |
---|
Type(s)
array
xml
The form XML definition.
since |
11.1 |
---|
Type(s)
object
forms
Form instances.
since |
11.1 |
---|
Type(s)
array