InputfieldWrapper::importArray() method

Import an array of Inputfield definitions to to this InputfieldWrapper instance

Your array should be an array of associative arrays, with each element describing an Inputfield. The following properties are required for each Inputfield definition:

  • type Which Inputfield module to use (may optionally exclude the "Inputfield" prefix).
  • name Name attribute to use for the Inputfield.
  • label Text label that appears above the Inputfield.

Example

// Example array for Inputfield definitions
array(
  array(
    'name' => 'fullname',
    'type' => 'text',
    'label' => 'Field label'
    'columnWidth' => 50,
    'required' => true,
  ),
  array(
    'name' => 'color',
    'type' => 'select',
    'label' => 'Your favorite color',
    'description' => 'Select your favorite color or leave blank if you do not have one.',
    'columnWidth' => 50,
    'options' => array(
       'red' => 'Brilliant Red',
       'orange' => 'Citrus Orange',
       'blue' => 'Sky Blue'
    )
  ),
  // alternative usage: associative array where name attribute is specified as key
  'my_fieldset' => array(
    'type' => 'fieldset',
    'label' => 'My Fieldset',
    'children' => array(
      'some_field' => array(
        'type' => 'text',
        'label' => 'Some Field',
      )
    )
);
// Note: you may alternatively use associative arrays where the keys are assumed to
// be the 'name' attribute.See the last item 'my_fieldset' above for an example. 

Usage

// basic usage
$inputfieldWrapper->importArray(array $a);

// usage with all arguments
$inputfieldWrapper->importArray(array $a, InputfieldWrapper $inputfields = null);

Arguments

NameType(s)Description
aarray

Array of Inputfield definitions

inputfields (optional)InputfieldWrapper

Specify the wrapper you want them added to, or omit to use current.

Return value

$this

Object instance it was called from (method supports fluent interface).


InputfieldWrapper methods and properties

API reference based on ProcessWire core version 3.0.236

Latest news

  • ProcessWire Weekly #521
    In the 521st issue of ProcessWire Weekly we'll check out the latest weekly update from Ryan, introduce a new third party module called FormBuilderHTMX, and more. Read on!
    Weekly.pw / 5 May 2024
  • ProFields Table Field with Actions support
    This week we have some updates for the ProFields table field (FieldtypeTable). These updates are primarily focused on adding new tools for the editor to facilitate input and management of content in a table field.
    Blog / 12 April 2024
  • Subscribe to weekly ProcessWire news

“To Drupal, or to ProcessWire? The million dollar choice. We decided to make an early switch to PW. And in retrospect, ProcessWire was probably the best decision we made. Thanks are due to ProcessWire and the amazing system and set of modules that are in place.” —Unni Krishnan, Founder of PigtailPundits