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 #544
    In the 150th issue of ProcessWire Weekly we'll check out brand-new third party module called Inputfield Dependency Helper, share some recent highlights from the support forum, and more. Read on!
    Weekly.pw / 12 October 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

“I am currently managing a ProcessWire site with 2 million+ pages. It’s admirably fast, and much, much faster than any other CMS we tested.” —Nickie, Web developer