Joomla CMS  4.2.2
Documentation des API du CMS Joomla en version 4.2.2
Référence de la classe Form

Fonctions membres publiques

 __construct ($name, array $options=[])
 
 bind ($data)
 
 getErrors ()
 
 getField ($name, $group=null, $value=null)
 
 getFieldAttribute ($name, $attribute, $default=null, $group=null)
 
 getFieldset ($set=null)
 
 getFieldsets ($group=null)
 
 getFormControl ()
 
 getGroup ($group, $nested=false)
 
 getInput ($name, $group=null, $value=null)
 
 getLabel ($name, $group=null)
 
 getName ()
 
 getValue ($name, $group=null, $default=null)
 
 renderField ($name, $group=null, $default=null, $options=[])
 
 renderFieldset ($name, $options=[])
 
 load ($data, $replace=true, $xpath=null)
 
 loadFile ($file, $reset=true, $xpath=null)
 
 removeField ($name, $group=null)
 
 removeGroup ($group)
 
 reset ($xml=false)
 
 setField (\SimpleXMLElement $element, $group=null, $replace=true, $fieldset='default')
 
 setFieldAttribute ($name, $attribute, $value, $group=null)
 
 setFields (&$elements, $group=null, $replace=true, $fieldset='default')
 
 setValue ($name, $group=null, $value=null)
 
 process ($data, $group=null)
 
 filter ($data, $group=null)
 
 validate ($data, $group=null)
 
 postProcess ($data, $group=null)
 
 getAttribute ($name, $default=null)
 
 getData ()
 
 getXml ()
 
 getFieldXml ($name, $group=null)
 

Fonctions membres publiques statiques

static addFieldPath ($new=null)
 
static addFormPath ($new=null)
 
static addRulePath ($new=null)
 
static addFilterPath ($new=null)
 
static getInstance ($name, $data=null, $options=[], $replace=true, $xpath=false)
 

Champs de données

 $repeat = false
 

Fonctions membres protégées

 bindLevel ($group, $data)
 
 findField ($name, $group=null)
 
findFieldsByFieldset ($name)
 
findFieldsByGroup ($group=null, $nested=false)
 
findGroup ($group)
 
 loadField ($element, $group=null, $value=null)
 
 syncPaths ()
 

Fonctions membres protégées statiques

static addNode (\SimpleXMLElement $source, \SimpleXMLElement $new)
 
static mergeNode (\SimpleXMLElement $source, \SimpleXMLElement $new)
 
static mergeNodes (\SimpleXMLElement $source, \SimpleXMLElement $new)
 

Attributs protégés

 $data
 
 $errors = []
 
 $name
 
 $options = []
 
 $xml
 

Attributs protégés statiques

static $forms = []
 

Description détaillée

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.

https://html.spec.whatwg.org/multipage/forms.html 1.7.0

Documentation des constructeurs et destructeur

◆ __construct()

__construct (   $name,
array  $options = [] 
)

Method to instantiate the form object.

Paramètres
string$nameThe name of the form.
array$optionsAn array of form options.
Depuis
1.7.0

Références $name, $options, et name.

Documentation des fonctions membres

◆ addFieldPath()

static addFieldPath (   $new = null)
static

Proxy for FormHelper::addFieldPath().

Paramètres
mixed$newA path or array of paths to add.
Renvoie
array The list of paths that have been added.
Depuis
1.7.0

Références FormHelper\addFieldPath().

Référencé par PluginModel\getForm(), TaskModel\getForm(), ContactModel\getForm(), StyleModel\getForm(), UpdateModel\getForm(), ModuleModel\getForm(), LanguagesModel\getForm(), Joomla\CMS\MVC\Model\loadForm(), et Joomla\CMS\MVC\Model\workflowAfterSave().

◆ addFilterPath()

static addFilterPath (   $new = null)
static

Proxy for FormHelper::addFilterPath().

Paramètres
mixed$newA path or array of paths to add.
Renvoie
array The list of paths that have been added.
Voir également
FormHelper::addFilterPath()
Depuis
4.0.0

Références FormHelper\addFilterPath().

◆ addFormPath()

◆ addNode()

static addNode ( \SimpleXMLElement  $source,
\SimpleXMLElement  $new 
)
staticprotected

Adds a new child SimpleXMLElement node to the source.

Paramètres
\SimpleXMLElement$sourceThe source element on which to append.
\SimpleXMLElement$newThe new element to append.
Renvoie
void
Depuis
1.7.0

Références $name, et $value.

◆ addRulePath()

static addRulePath (   $new = null)
static

Proxy for FormHelper::addRulePath().

Paramètres
mixed$newA path or array of paths to add.
Renvoie
array The list of paths that have been added.
Voir également
FormHelper::addRulePath()
Depuis
1.7.0

Références FormHelper\addRulePath().

Référencé par LanguagesModel\getForm().

◆ bind()

bind (   $data)

Method to bind data to the form.

Paramètres
mixed$dataAn array or object of data to bind to the form.
Renvoie
boolean True on success.
Depuis
1.7.0

Références $data, $this, et null.

Référencé par SubformField\loadSubFormData().

◆ bindLevel()

bindLevel (   $group,
  $data 
)
protected

Method to bind data to the form for the group level.

Paramètres
string$groupThe dot-separated form group path on which to bind the data.
mixed$dataAn array or object of data to bind to the form for the group level.
Renvoie
void
Depuis
1.7.0

Références $data, elseif, et ArrayHelper\isAssociative().

◆ filter()

filter (   $data,
  $group = null 
)

Method to filter the form data.

Paramètres
array$dataAn array of field values to filter.
string$groupThe dot-separated form group path on which to filter the fields.
Renvoie
mixed Array or false.
Depuis
4.0.0

Références $data, $field, $fields, $groups, $input, $key, $name, $output, et $this.

◆ findField()

findField (   $name,
  $group = null 
)
protected

Method to get a form field represented as an XML element object.

Paramètres
string$nameThe name of the form field.
string$groupThe optional dot-separated form group path on which to find the field.
Renvoie
|boolean The XML element object for the field or boolean false on error.
Depuis
1.7.0

Références $field, $fields, $name, $names, $this, et $tmp.

◆ findFieldsByFieldset()

& findFieldsByFieldset (   $name)
protected

Method to get an array of <field> elements from the form XML document which are in a specified fieldset by name.

Paramètres
string$nameThe name of the fieldset.
Renvoie
[]|boolean Boolean false on error or array of SimpleXMLElement objects.
Depuis
1.7.0

Références $fields, $name, et $this.

◆ findFieldsByGroup()

& findFieldsByGroup (   $group = null,
  $nested = false 
)
protected

Method to get an array of <field> elements from the form XML document which are in a control group by name.

Paramètres
mixed$groupThe 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.
boolean$nestedTrue to also include fields in nested groups that are inside of the group for which to find fields.
Renvoie
[]|boolean Boolean false on error or array of SimpleXMLElement objects.
Depuis
1.7.0

Références $field, $fields, $names, $this, $tmp, et elseif.

◆ findGroup()

& findGroup (   $group)
protected

Method to get a form field group represented as an XML element object.

Paramètres
string$groupThe dot-separated form group path on which to find the group.
Renvoie
[]|boolean An array of XML element objects for the group or boolean false on error.
Depuis
1.7.0

Références $fields, $groups, $i, $n, $names, $this, et $tmp.

◆ getAttribute()

getAttribute (   $name,
  $default = null 
)

Returns the value of an attribute of the form itself

Paramètres
string$nameName of the attribute to get
mixed$defaultOptional value to return if attribute not found
Renvoie
mixed Value of the attribute / default
Depuis
3.2

Références $default, $value, et null.

◆ getData()

getData ( )

Getter for the form data

Renvoie
Registry Object with the data
Depuis
3.2

Références $data.

◆ getErrors()

getErrors ( )

Return all errors, if any.

Renvoie
array Array of error messages or RuntimeException objects.
Depuis
1.7.0

◆ getField()

getField (   $name,
  $group = null,
  $value = null 
)

Method to get a form field represented as a FormField object.

Paramètres
string$nameThe name of the form field.
string$groupThe optional dot-separated form group path on which to find the field.
mixed$valueThe optional value to use as the default for the field.
Renvoie
FormField|boolean The FormField object for the field or boolean false on error.
Depuis
1.7.0

Références $name, $this, et $value.

◆ getFieldAttribute()

getFieldAttribute (   $name,
  $attribute,
  $default = null,
  $group = null 
)

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.

Paramètres
string$nameThe name of the form field for which to get the attribute value.
string$attributeThe name of the attribute for which to get a value.
mixed$defaultThe optional default value to use if no attribute value exists.
string$groupThe optional dot-separated form group path on which to find the field.
Renvoie
mixed The attribute value for the field.
Depuis
1.7.0
Exceptions

Références $default, $name, et $this.

◆ getFieldset()

getFieldset (   $set = null)

Method to get an array of FormField objects in a given fieldset by name. If no name is given then all fields are returned.

Paramètres
string$setThe optional name of the fieldset.
Renvoie
FormField[] The array of FormField objects in the fieldset.
Depuis
1.7.0

Références $field, $fields, et $groups.

◆ getFieldsets()

getFieldsets (   $group = null)

Method to get an array of fieldset objects optionally filtered over a given field group.

Paramètres
string$groupThe dot-separated form group path on which to filter the fieldsets.
Renvoie
array The array of fieldset objects.
Depuis
1.7.0

Références $fieldsets, $name, $this, $tmp, et $value.

◆ getFieldXml()

getFieldXml (   $name,
  $group = null 
)

Method to get a form field represented as an XML element object.

Paramètres
string$nameThe name of the form field.
string$groupThe optional dot-separated form group path on which to find the field.
Renvoie
|boolean The XML element object for the field or boolean false on error.
Depuis
3.7.0

Références $name.

◆ getFormControl()

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: <input name="foo" /> and <input name="bar" />. If the form control is set to 'joomla' however, the fields would be rendered like: <input name="joomla[foo]" /> and <input name="joomla[bar]" />.

Renvoie
string The form control string.
Depuis
1.7.0

◆ getGroup()

getGroup (   $group,
  $nested = false 
)

Method to get an array of FormField objects in a given field group by name.

Paramètres
string$groupThe dot-separated form group path for which to get the form fields.
boolean$nestedTrue to also include fields in nested groups that are inside of the group for which to find fields.
Renvoie
FormField[] The array of FormField objects in the field group.
Depuis
1.7.0

Références $field, $fields, et $groups.

◆ getInput()

getInput (   $name,
  $group = null,
  $value = null 
)

Method to get a form field markup for the field input.

Paramètres
string$nameThe name of the form field.
string$groupThe optional dot-separated form group path on which to find the field.
mixed$valueThe optional value to use as the default for the field.
Renvoie
string The form field markup.
Depuis
1.7.0

Références $field, $name, et $value.

◆ getInstance()

static getInstance (   $name,
  $data = null,
  $options = [],
  $replace = true,
  $xpath = false 
)
static

Method to get an instance of a form.

Paramètres
string$nameThe name of the form.
string$dataThe name of an XML file or string to load as the form definition.
array$optionsAn array of form options.
boolean$replaceFlag to toggle whether form fields should be replaced if a field already exists with the same group/name.
string | boolean$xpathAn optional xpath to search for the fields.
Renvoie
Form Form instance.
Depuis
1.7.0
Obsolète:
5.0 Use the FormFactory service from the container
Exceptions

Références $data, $name, $options, class, et Factory\getContainer().

Référencé par ContactModel\buildContactExtendedData(), SetupModel\getForm(), ChecksModel\getForm(), UpdateModel\getForm(), LanguagesModel\getForm(), TinymcebuilderField\getLayoutData(), FormModel\loadForm(), SubformField\loadSubForm(), et SubformField\loadSubFormData().

◆ getLabel()

getLabel (   $name,
  $group = null 
)

Method to get the label for a field input.

Paramètres
string$nameThe name of the form field.
string$groupThe optional dot-separated form group path on which to find the field.
Renvoie
string The form field label.
Depuis
1.7.0

Références $field, et $name.

◆ getName()

getName ( )

Method to get the form name.

Renvoie
string The name of the form.
Depuis
1.7.0

Références $name.

Référencé par SubformField\loadSubFormData().

◆ getValue()

getValue (   $name,
  $group = null,
  $default = null 
)

Method to get the value of a field.

Paramètres
string$nameThe name of the field for which to get the value.
string$groupThe optional dot-separated form group path on which to get the value.
mixed$defaultThe optional default value of the field value is empty.
Renvoie
mixed The value of the field or the default value if empty.
Depuis
1.7.0

Références $default, $name, et $return.

◆ getXml()

getXml ( )

Method to get the XML form object

Renvoie
The form XML object
Depuis
3.2

Références $xml.

◆ load()

load (   $data,
  $replace = true,
  $xpath = null 
)

Method to load the form description from an XML string or object.

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.

Paramètres
string$dataThe name of an XML string or object.
boolean$replaceFlag to toggle whether form fields should be replaced if a field already exists with the same group/name.
string$xpathAn optional xpath to search for the fields.
Renvoie
boolean True on success, false otherwise.
Depuis
1.7.0

Références $data, $field, $fields, $groups, et elseif.

◆ loadField()

loadField (   $element,
  $group = null,
  $value = null 
)
protected

Method to load, setup and return a FormField object based on field data.

Paramètres
string$elementThe XML element object representation of the form field.
string$groupThe optional dot-separated form group path on which to find the field.
mixed$valueThe optional value to use as the default for the field.
Renvoie
FormField|boolean The FormField object for the field or boolean false on error.
Depuis
1.7.0

Références $default, $field, $lang, $this, $type, $value, Text\_(), class, Factory\getContainer(), Joomla\Database\getDatabase(), Factory\getLanguage(), FormHelper\loadFieldType(), et null.

◆ loadFile()

loadFile (   $file,
  $reset = true,
  $xpath = null 
)

Method to load the form description from an XML file.

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.

Paramètres
string$fileThe filesystem path of an XML file.
boolean$resetFlag to toggle whether form fields should be replaced if a field already exists with the same group/name.
string$xpathAn optional xpath to search for the fields.
Renvoie
boolean True on success, false otherwise.
Depuis
1.7.0

Références $xml, et Path\find().

Référencé par StyleModel\preprocessForm(), et CategoryModel\preprocessForm().

◆ mergeNode()

static mergeNode ( \SimpleXMLElement  $source,
\SimpleXMLElement  $new 
)
staticprotected

Update the attributes of a child node

Paramètres
\SimpleXMLElement$sourceThe source element on which to append the attributes
\SimpleXMLElement$newThe new element to append
Renvoie
void
Depuis
1.7.0

Références $name, et $value.

◆ mergeNodes()

static mergeNodes ( \SimpleXMLElement  $source,
\SimpleXMLElement  $new 
)
staticprotected

Merges new elements into a source <fields> element.

Paramètres
\SimpleXMLElement$sourceThe source element.
\SimpleXMLElement$newThe new element to merge.
Renvoie
void
Depuis
1.7.0

Références $fields, $name, $type, et $value.

◆ postProcess()

postProcess (   $data,
  $group = null 
)

Method to post-process form data.

Paramètres
array$dataAn array of field values to post-process.
string$groupThe optional dot-separated form group path on which to filter the fields to be validated.
Renvoie
mixed Array or false.
Depuis
4.0.0

Références $data, $field, $fields, $groups, $input, $key, $name, $output, et $this.

◆ process()

process (   $data,
  $group = null 
)

Method to process the form data.

Paramètres
array$dataAn array of field values to filter.
string$groupThe dot-separated form group path on which to filter the fields.
Renvoie
mixed Array or false.
Depuis
4.0.0

Références $data.

◆ removeField()

removeField (   $name,
  $group = null 
)

Method to remove a field from the form definition.

Paramètres
string$nameThe name of the form field for which remove.
string$groupThe optional dot-separated form group path on which to find the field.
Renvoie
boolean True on success, false otherwise.
Depuis
1.7.0
Exceptions

Références $name, et $this.

◆ removeGroup()

removeGroup (   $group)

Method to remove a group from the form definition.

Paramètres
string$groupThe dot-separated form group path for the group to remove.
Renvoie
boolean True on success.
Depuis
1.7.0
Exceptions

Références $this.

◆ renderField()

renderField (   $name,
  $group = null,
  $default = null,
  $options = [] 
)

Method to get a control group with label and input.

Paramètres
string$nameThe name of the field for which to get the value.
string$groupThe optional dot-separated form group path on which to get the value.
mixed$defaultThe optional default value of the field value is empty.
array$optionsAny options to be passed into the rendering of the field
Renvoie
string A string containing the html for the control group
Depuis
3.2.3

Références $default, $field, $name, et $options.

◆ renderFieldset()

renderFieldset (   $name,
  $options = [] 
)

Method to get all control groups with label and input of a fieldset.

Paramètres
string$nameThe name of the fieldset for which to get the values.
array$optionsAny options to be passed into the rendering of the field
Renvoie
string A string containing the html for the control groups
Depuis
3.2.3

Références $field, $fields, $html, $name, et $options.

◆ reset()

reset (   $xml = false)

Method to reset the form data store and optionally the form XML definition.

Paramètres
boolean$xmlTrue to also reset the XML form definition.
Renvoie
boolean True on success.
Depuis
1.7.0

Références $xml.

◆ setField()

setField ( \SimpleXMLElement  $element,
  $group = null,
  $replace = true,
  $fieldset = 'default' 
)

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.

Paramètres
\SimpleXMLElement$elementThe XML element object representation of the form field.
string$groupThe optional dot-separated form group path on which to set the field.
boolean$replaceTrue to replace an existing field if one already exists.
string$fieldsetThe name of the fieldset we are adding the field to.
Renvoie
boolean True on success.
Depuis
1.7.0
Exceptions

Références $fields, $path, et $this.

◆ setFieldAttribute()

setFieldAttribute (   $name,
  $attribute,
  $value,
  $group = null 
)

Method to set an attribute value for a field XML element.

Paramètres
string$nameThe name of the form field for which to set the attribute value.
string$attributeThe name of the attribute for which to set a value.
mixed$valueThe value to set for the attribute.
string$groupThe optional dot-separated form group path on which to find the field.
Renvoie
boolean True on success.
Depuis
1.7.0
Exceptions

Références $name, $this, et $value.

Référencé par FormModel\preprocessForm(), et ItemsModel\preprocessForm().

◆ setFields()

setFields ( $elements,
  $group = null,
  $replace = true,
  $fieldset = 'default' 
)

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.

Paramètres
array&$elementsThe array of XML element object representations of the form fields.
string$groupThe optional dot-separated form group path on which to set the fields.
boolean$replaceTrue to replace existing fields if they already exist.
string$fieldsetThe name of the fieldset we are adding the field to.
Renvoie
boolean True on success.
Depuis
1.7.0
Exceptions

Références $return, et $this.

◆ setValue()

setValue (   $name,
  $group = null,
  $value = null 
)

Method to set the value of a field. If the field does not exist in the form then the method will return false.

Paramètres
string$nameThe name of the field for which to set the value.
string$groupThe optional dot-separated form group path on which to find the field.
mixed$valueThe value to set for the field.
Renvoie
boolean True on success.
Depuis
1.7.0

Références $name, et $value.

◆ syncPaths()

syncPaths ( )
protected

Method to synchronize any field, form or rule paths contained in the XML document.

Renvoie
boolean True on success.
Depuis
1.7.0

Références $path, $prefix, $this, FormHelper\addFieldPrefix(), FormHelper\addFilterPrefix(), FormHelper\addFormPrefix(), FormHelper\addRulePrefix(), et JPATH_ROOT.

◆ validate()

validate (   $data,
  $group = null 
)

Method to validate form data.

Validation warnings will be pushed into JForm::errors and should be retrieved with JForm::getErrors() when validate returns boolean false.

Paramètres
array$dataAn array of field values to validate.
string$groupThe optional dot-separated form group path on which to filter the fields to be validated.
Renvoie
boolean True on success.
Depuis
1.7.0

Références $data, $disabled, $field, $fields, $groups, $input, $key, $name, $return, $this, Text\_(), elseif, et Text\sprintf().

Documentation des champs

◆ $data

$data
protected

◆ $errors

$errors = []
protected

◆ $forms

$forms = []
staticprotected

◆ $name

$name
protected

◆ $options

$options = []
protected

◆ $repeat

$repeat = false

◆ $xml

$xml
protected

La documentation de cette classe a été générée à partir du fichier suivant :