FormBuilderField::addField()

Add new field by specifying name, type and label

Available since version 0.5.7.

Usage

// basic usage
$formBuilderField = $formBuilderField->addField(string $name);

// usage with all arguments
$formBuilderField = $formBuilderField->addField(string $name, string $type = '', string $label = '', array $options = []);

Arguments

NameType(s)Description
$namestring

Name of field (_a-zA-Z0-9)

$type (optional)string

Type of field, which is Inputfield name minus "Inputfield" prefix, i.e. "Text", "URL", "Select", etc. Default:Text

$label (optional)string

Label for this field

$options (optional)array

Additional options

  • description (string): Additional text that appears above input.
  • notes (string): Additional text that appears below input.
  • columnWidth (int): Width of field as a percent between 10 and 100 Default:100
  • required (bool): Specify true to make field required Default:false
  • Additional Inputfield properties unique to each type may be added as well.

Return value

FormBuilderField

Returns the added FormBuilderField object

Exceptions

Method can throw exceptions on error:

  • FormBuilderException - If name of field being added already exists


FormBuilderField methods and properties

API reference based on ProcessWire core version 3.0.251