Skip to content

Single element

A single element repeats one input. The submitted value is a flat list of strings.

Without #element, each row is a text field.

$form['tags'] = [
'#type' => 'element_multiple',
'#title' => $this->t('Tags'),
'#default_value' => ['One', 'Two', 'Three'],
];

Three text fields and one empty row, each with a drag handle, an add button and a remove button, and an Add more control below.

The value is ['One', 'Two', 'Three']. The empty fourth row is dropped.

Set #element to any input element. Use #title_display => 'invisible' so the title does not repeat in every row.

$form['emails'] = [
'#type' => 'element_multiple',
'#title' => $this->t('Email addresses'),
'#element' => [
'#type' => 'email',
'#title' => $this->t('Email address'),
'#title_display' => 'invisible',
'#placeholder' => $this->t('name@example.com'),
],
'#default_value' => ['example@example.com'],
];

The plus button of a row adds a blank row right after it. The page does not reload.

The list after the plus button of the first row was clicked. A new empty row sits between One and Two.