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 #551
    In the 551st issue of ProcessWire Weekly we'll check out what's new in the core this week, share a new weekly poll, and more. Read on!
    Weekly.pw / 1 December 2024
  • Custom Fields Module
    This week we look at a new ProFields module named Custom Fields. This module provides a way to rapidly build out ProcessWire fields that contain any number of subfields/properties within them.
    Blog / 30 August 2024
  • Subscribe to weekly ProcessWire news

“Indeed, if ProcessWire can be considered as a CMS in its own right, it also offers all the advantages of a CMF (Content Management Framework). Unlike other solutions, the programmer is not forced to follow the proposed model and can integrate his/her ways of doing things.” —Guy Verville, Spiria Digital Inc.