FormBuilderForm::addField()
Create and add a new field by specifying name, type and label
You may also specify a FormBuilderField object for the first argument ($name), in which case all following arguments are optional.
Versions prior to 0.5.7 can use the FormBuilderForm::add() method, but this method requires a FormBuilderField object.
Available since version 0.5.7.
Example
$form = $forms->addForm('contact');
$form->addField('first_name', 'Text', 'First name');
$form->addField('last_name', 'Text', 'Last name');
$form->addField('email', 'Email', 'Your email');
$form->addField('message', 'Textarea', 'Message');
$form->save();Usage
// basic usage
$formBuilderField = $formBuilderForm->addField($name);
// usage with all arguments
$formBuilderField = $formBuilderForm->addField($name, string $type = '', string $label = '', array $options = []);Arguments
| Name | Type(s) | Description |
|---|---|---|
$name | string FormBuilderField | Name of field (_a-zA-Z0-9) or a FormBuilderField object. |
$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
|
Return value
FormBuilderFieldReturns the added FormBuilderField object
FormBuilderForm methods and properties
API reference based on ProcessWire core version 3.0.252