Joomla subform Form Field Type

The subform form field type provides a method for using XML forms inside one another or reuse forms inside an existing form. If attribute multiple is set to true then the included form will be repeatable.

The Field has two predefined layouts for displaying the subform as either a a table or as a div container, as well as support for custom layouts.

The subform form field does not provide the Validation and Filters for child fields.

XML field Definition

<field name="mysubform" 
type="subform"
formsource="path/to/exampleform.xml"
label="Subform Field" />

Additional Parameters

formsource: The form source to be included. A relative path to the xml file (relative to the root folder for the installed Joomla site) or a valid form name which can be found by the Form::getInstance() method.

multiple: It sets whether the subform fields are repeatable or not.

min: The count of minimum repeating in multiple mode.

max: The count of maximum repeating in multiple mode.

groupByFieldset: It sets whether to group the subform fields by its fieldset (true or false). The default value is false.

buttons: It sets which buttons to show in the multiple mode. There are three buttons: add, remove, move. The default value is add,remove,move.

layout: The name of the layout to use when displaying the subform fields. The layouts are saved in the folder: layouts/joomla/form/field/subform. For example,

  • layout="joomla.form.field.subform.repeatable-table"
  • layout="joomla.form.field.subform.repeatable"
  • layout="joomla.form.field.subform.default"

How to Get Values

The values are stored as object. For example, if subform field (with name mysubform) contains two fields - alpha and beta.

$mysubform = $this->params->get('mysubform');
$arr = (array) $mysubform;
foreach ($arr as $value)
{
 echo $value->alpha;
 echo $value->beta;
}

Example

1. Users Component in Options

<field
name="domains"
type="subform"
label="COM_USERS_CONFIG_FIELD_DOMAINS_LABEL"
description="COM_USERS_CONFIG_FIELD_DOMAINS_DESC"
multiple="true"
layout="joomla.form.field.subform.repeatable-table"
formsource="administrator/components/com_users/models/forms/config_domain.xml" />