Form Element Multiplier

Component ID

2044441

Component name

Form Element Multiplier

Component type

module

Maintenance status

Development status

Component security advisory coverage

not-covered

Component created

Component changed

Component body

This module provides a kind of form container which allows to multiply its child elements to give a system of multiple values. The form element multiplier is presented as a table to which you can add, remove and order rows.

Usage

Create a multiplier element is as simple as create a container or a fieldset, just look at the following example :


$form = array();

$form['multiplier'] = array(
  '#type' => 'multiplier',
  '#title' => t("Multiplier example"),
  '#default_value' => variable_get('multiplier', array()),
);

$form['multiplier']['text'] = array(
  '#type' => 'textfield',
  '#title' => t("Text"),
  '#default_value' => "Lorem ipsum...",
  '#required' => TRUE,
  '#size' => 30,
);

$form['multiplier']['select'] = array(
  '#type' => 'select',
  '#title' => t("Select"),
  '#options' => array(
    0 => 'Option 1',
    1 => 'Option 2',
    2 => 'Option 3',
  ),
);

$form['multiplier']['container'] = array(
  '#type' => 'container',
  '#title' => t("Container"),
  '#tree' => TRUE,
  'child_1' => array(
    '#type' => 'textfield',
    '#title' => t("Child 1"),
    '#size' => 20,
  ),
  'child_2' => array(
    '#type' => 'checkbox',
    '#title' => t("Child 2"),
  ),
);

return system_settings_form($form);

Features

The multiplier element defines 2 new properties : #min_rows and #max_rows. As you could guess, these ones give the possibility to set a minimum and a maximum number of rows that the user can fill in.
Consequently, set the multiplier as required is equivalent to set #min_rows to "1", implying the user must fill in at least one row, and conversely, set a value for #min_rows makes the multiplier required.