Inputfield / InputfieldWrapper

Inputfield is the abstract base class for all form input widgets in ProcessWire

InputfieldWrapper extends it to hold child Inputfields (forms, fieldsets). Together they are the backbone of ProcessWire's form rendering and input processing.

Inputfields are modules — get a new instance via $modules->get():

$f = $modules->get('InputfieldText');
$f->label = 'Your Name';
$f->attr('name', 'your_name');
$f->attr('value', '');
$f->required = true;
Getting instances

Via $modules->get()

$f      = $modules->get('InputfieldText');   /** @var InputfieldText $f */
$form   = $modules->get('InputfieldForm');   /** @var InputfieldForm $form */
$select = $modules->get('InputfieldSelect'); /** @var InputfieldSelect $select */

Each call returns a fresh instance. This is the standard approach when building forms manually.

Via InputfieldWrapper magic property

One benefit of this approach is that it enables IDEs to identify the Inputfield type without a /** @var InputfieldText $f */ type hint.

$f = $wrapper->InputfieldText;       // new InputfieldText, not yet added to wrapper
$f = $wrapper->InputfieldSelect;

Note: InputfieldForm is a type of InputfieldWrapper.

Via $wrapper->new()

Creates an Inputfield, sets basic properties, adds it to the wrapper, and returns it. Short type names are accepted (without the "Inputfield" prefix).

/** @var InputfieldText $f */
$f = $wrapper->new('InputfieldText', 'phone', 'Phone Number');
$f = $wrapper->new('text', 'email', 'Email', ['required' => true]);
/** @var InputfieldSelect $f */
$f = $wrapper->new('select', 'color', 'Color', ['description' => 'Choose one']);

Arguments: $typeName, $name = '', $label = '', $settings = []. Any of $name, $label, or $settings can be replaced with an array to be treated as $settings.

Inputfield

Attributes

attr($key, $value)

Get or set an HTML attribute. The primary method for working with input attributes.

$f->attr('name', 'email');
$f->attr('value', 'default@example.com');
$name = $f->attr('name'); // get

// Set multiple attributes at once
$f->attr([
    'name' => 'email',
    'value' => 'default@example.com',
    'placeholder' => 'you@example.com',
]);

// Set name and id to the same value
$f->attr('name+id', 'email');

// Get all attributes
$attrs = $f->attr(true);

Passing false as the value removes most boolean attributes when setting them. To remove any attribute explicitly, use $f->removeAttr('attributeName').

val($value)

Shortcut getter/setter for the value attribute.

$current = $f->val();      // get
$f->val('new value');      // set

name() / id() / class()

Chainable getter/setter methods:

$f->name('email')->id('input-email')->class('uk-input');
$name = $f->name(); // get

Labels and text

PropertyDescription
labelPrimary label (appears above input)
descriptionDetailed description (appears under label)
notesNotes (appears under input)
detailAdditional detail text (appears under notes, 3.0.140+
iconFont Awesome icon name, without "fa-" prefix
headText between label and description
tabLabelLabel when rendered as its own tab
prependMarkupMarkup prepended inside the content container
appendMarkupMarkup appended inside the content container
requiredLabelCustom label for the required-field validation message

All support magic property set/get (this is the most commonly used syntax):

$f->label = 'Email Address';
$f->description = 'Enter your primary email';
$f->notes = 'We will not share your email';
$f->icon = 'envelope';

Collapsed state

Controls how the Inputfield renders in the admin. Set via the collapsed property using one of the constants below:

$f->collapsed = Inputfield::collapsedYes;
$f->collapsed = Inputfield::collapsedBlankAjax;
ConstantValueDescription
collapsedNo0Open (default)
collapsedYes1Collapsed; user can open
collapsedBlank2Collapsed only when blank/empty
collapsedHidden4Hidden; not rendered at all
collapsedPopulated5Collapsed only when populated
collapsedNoLocked6Visible but not editable
collapsedBlankLocked7Collapsed when blank; visible-locked when populated
collapsedYesLocked8Collapsed; locked when visible
collapsedLocked8Alias for collapsedYesLocked
collapsedNever9Cannot be collapsed by the user
collapsedYesAjax10Collapsed; content loaded via Ajax when opened
collapsedBlankAjax11Collapsed when blank; content loaded via Ajax
collapsedTab20Rendered as its own tab
collapsedTabAjax21Rendered as its own tab; content loaded via Ajax
collapsedTabLocked22Rendered as its own tab; locked (not editable)

Visibility and layout

showIf and requiredIf enable the conditional visibility and required state of an Inputfield. These are often referred to as Inputfield dependencies. These properties accept ProcessWire selector strings referencing other field names in the same form. Note that they support a reduced set of selector features, so test and verify before assuming a showIf/requiredIf condition works properly. Supported operators include =, !=, <', <=, >, >=, *=. OR conditions are also supported for field name and value.

// show only when Inputfield `info_type` field has value 'contact'.
$f->showIf = 'info_type=contact';

// required only when condition is met ($f->required must be true)
$f->requiredIf = 'info_type=contact';
$f->required = true;

// percentage width for 2+ Inputfields in a row (10-100; 0 treated as 100)
$f->columnWidth = 50;

When matching Page reference fields in a showIf or requiredIf selector, note that you are matching by page ID.

Skip label

Controls label rendering. Use skipLabel constants:

ConstantValueDescription
skipLabelNofalseRender label normally (default)
skipLabelFortrueRender label without for attribute
skipLabelHeader2Don't render the label element at all
skipLabelBlank4Skip label if it is blank
skipLabelMarkup8Allow HTML markup in the label string
$f->skipLabel = Inputfield::skipLabelHeader; // no label rendered
$f->skipLabel = Inputfield::skipLabelMarkup; // allow <strong> etc. in label

Class manipulation

$f->addClass('uk-input uk-form-large');      // add to input element
$f->addClass('highlight', 'wrapClass');      // add to .Inputfield wrapper element
$f->addClass('wrap:card, header:card-head'); // formatted element-specific classes

if($f->hasClass('required')) { ... }

$f->removeClass('old-class');

The $property argument accepts: 'class', 'wrapClass', 'headerClass', 'contentClass'. The short names 'input', 'wrap', 'header', and 'content' are also accepted where class-property names are parsed.

You can also use fluent class methods for common wrapper elements:

$f->wrapClass('card');          // add class to outer .Inputfield wrapper
$f->headerClass('card-head');   // add class to .InputfieldHeader
$f->contentClass('card-body');  // add class to .InputfieldContent

$wrapClass = $f->wrapClass();   // get current wrapper classes

Processing and validation

Common form-handling pattern:

/** @var InputfieldForm $form */
$form = $modules->get('InputfieldForm');

/** @var InputfieldEmail $f */
$f = $modules->get('InputfieldEmail');
$f->attr('name', 'email');
$f->label = 'Your email';
$f->required = true;
$form->add($f);

/** @var InputfieldSubmit $f */
$f = $modules->get('InputfieldSubmit');
$f->attr('name', 'submit_send');
$f->value = 'Send';
$form->add($f);

if($input->post('submit_send')) {
    $form->processInput($input->post);
    if(count($form->getErrors())) {
        // re-render form with errors
    } else {
        /** @var InputfieldEmail $f */
        $f = $form->getChildByName('email');
        $email = $f->value;
        // handle submission
        // ...
        $session->location('/success/page/url');
    }
}

echo $form->render();

More modern form handling pattern:

/** @var InputfieldForm $form */
$form = $modules->get('InputfieldForm');

$f = $form->InputfieldEmail;
$f->attr('name', 'email');
$f->label = 'Your email';
$f->required = true;
$form->add($f);

$f = $form->InputfieldSubmit;
$f->attr('name', 'submit_send');
$f->val('Send');
$form->add($f);

if($form->isSubmitted('submit_send')) {
    if($form->process()) {
        $email = $form->getValueByName('email');
        // handle submission
        $session->location('/success/page/url');
    } else {
        // re-render form with errors
    }
}

echo $form->render();

process()

Process an InputfieldForm using the form's configured method (post by default, or get when $form->attr('method', 'get')). Returns true when processing completed with no errors, or false when validation errors were recorded.

if($form->process()) {
    // form processed successfully
} else {
    $errors = $form->getErrors();
    $errorFields = $form->getErrorInputfields();
}

This is often more convenient than processInput() at the form level because it does not require passing $input->post or $input->get, and it gives you a success/failure boolean directly.

CSRF protection

InputfieldForm has CSRF protection enabled by default for POST forms.

$form = $modules->get('InputfieldForm');
$form->protectCSRF = true; // default

When the form renders, it automatically includes the CSRF token input. When you call $form->process() or $form->processInput($input->post), the token is validated. If the token is invalid, ProcessWire throws a WireException.

Disable CSRF protection only for trusted/internal forms:

$form->protectCSRF = false;

CSRF protection is applied to POST forms, not GET forms.

processInput(WireInputData $input)

Process submitted input data for this Inputfield and populate its value.

$f->processInput($input->post);
$value = $f->val(); // now contains the processed value

isEmpty()

Returns true if the Inputfield's current value is considered empty.

error($text) / getErrors($clear) / clearErrors()

$f->error('Value is not valid');
$errors = $f->getErrors();       // array of error strings
$errors = $f->getErrors(true);   // get and clear
$f->clearErrors();

Rendering

echo $f->render();        // render as an editable input
echo $f->renderValue();   // render as a value display (no input)

editable($setEditable)

Get or set whether the Inputfield renders in editable or value-display mode.

$f->editable(false); // lock; renderValue() used instead of render()
$isEditable = $f->editable();

Hierarchy

$parent = $f->parent();       // get parent InputfieldWrapper
$parents = $f->getParents();  // all ancestor wrappers
$root = $f->getRootParent();  // top-level wrapper
$form = $f->getForm();        // nearest InputfieldForm ancestor
InputfieldWrapper

Extends Inputfield to hold an ordered set of child Inputfields. Base class for forms (InputfieldForm) and fieldsets (InputfieldFieldset).

Adding children

$wrapper->add($f);              // append an Inputfield
$wrapper->add('InputfieldText'); // shortcut: create and add by type name
$wrapper->prepend($header);
$wrapper->append($submit);
$wrapper->insertBefore($phone, $email);
$wrapper->insertAfter($address, $phone);

Creating and adding in one call

// $wrapper->new() creates, configures, adds, and returns the Inputfield
$f = $wrapper->new('text', 'first_name', 'First Name');
$f->required = true; // chainable further configuration

Removing children

$wrapper->remove($f);
$wrapper->remove('phone');       // remove by name, returns the wrapper
$removed = $wrapper->removeByName('phone'); // remove by name, returns removed field or null

Accessing children

$all      = $wrapper->children();              // all children as InputfieldsArray
$required = $wrapper->children('required=1');  // filtered by selector
$f        = $wrapper->getChildByName('email'); // single child by name
$f        = $wrapper->getByName('email');      // alias
$f        = $wrapper->get('email');            // also works (WireData)
$value    = $wrapper->getValueByName('email'); // get a child's value directly
$found    = $wrapper->find('required=1');      // recursive selector search

Batch import

// Import from an array of definitions
$wrapper->importArray([
    [
        'type' => 'InputfieldText',
        'name' => 'first',
        'label' => 'First Name',
        'attr' => [
            'placeholder' => 'Ada',
        ],
    ],
    [
        'type' => 'InputfieldEmail',
        'name' => 'email',
        'label' => 'Email',
        'required' => true,
    ],
]);

Processing and errors

$wrapper->processInput($input->post);   // processes all children
$errors = $wrapper->getErrors();        // errors from all children
$empty  = $wrapper->getEmpty();         // required children that are empty
$badFields = $wrapper->getErrorInputfields(); // children with errors

isEmpty() on a wrapper returns true only if ALL children are empty.

Rendering

echo $wrapper->render();       // render all children
echo $wrapper->renderValue();  // render all children in value-display mode

Markup customization

Override the default <ul>/<li> structure globally:

InputfieldWrapper::setMarkup([
    'list' => "<div {attrs}>{out}</div>",
    'item' => "<div {attrs}>{out}</div>",
]);

InputfieldWrapper::setClasses([
    'list' => 'my-form',
    'item' => 'my-field {class}',
]);

Placeholders: {attrs}, {out}, {class}, {name}, {for}.

UIKit theme settings

These properties are recognized by AdminThemeUikit to control visual presentation:

PropertyValuesDescription
themeOffset's', 'm', 'l'Margin/offset size
themeBorder'none', 'card', 'hide', 'line'Border style
themeInputSize's', 'm', 'l'Input size
themeInputWidth'xs', 's', 'm', 'l', 'f'Input width
themeColor'primary', 'secondary', 'warning', etc.Color theme
themeBlankboolNo container/border
Notes
  • Source files: wire/core/Inputfield/Inputfield.php and InputfieldWrapper.php
  • Inputfield extends WireData and implements Module. All WireData methods are available.
  • $modules->get('InputfieldText') and $form->InputfieldText return a fresh instance each call (not a singleton).
  • showIf and requiredIf selectors reference other Inputfield names or IDs in the same rendered form.
  • Each Inputfield processInput() is called automatically by InputfieldWrapper::processInput() — you usually call it on the form, not individual fields.
  • renderValue() is used in contexts where editing is not allowed (locked fields, view-only displays).
  • collapsedHidden (4) hides the field entirely from render — it won't appear in the DOM at all.
  • The Tab constants (collapsedTab, collapsedTabAjax, collapsedTabLocked) render the field as a separate admin tab rather than a collapsible section.
  • Ajax collapse constants load field content only when the user opens the collapsed section, improving page load on fields with heavy output.
API reference: methods, properties, hooks

Click any linked item for full usage details and examples. Hookable methods are indicated with the icon. In addition to those shown below, the InputfieldWrapper class also inherits all the methods and properties of: Inputfield, WireData and Wire.

Show class?     Show args?       Only hookable?    

Manipulation

NameReturnSummary 
InputfieldWrapper::add($item)
Inputfield InputfieldWrapper this

Add an Inputfield item as a child (also accepts array definition)

 
InputfieldWrapper::append(Inputfield $item)
$this

Append an Inputfield to this instance’s children.

 
InputfieldWrapper::import($items)
$this

Import the given Inputfield items as children

 
InputfieldWrapper::importArray(array $a)
$this

Import an array of Inputfield definitions to to this InputfieldWrapper instance

 
InputfieldWrapper::insert($item, $existingItem)
$this

Insert new or existing Inputfield before or after another

 
InputfieldWrapper::insertAfter($item, $existingItem)
$this

Insert one Inputfield after one that’s already there.

 
InputfieldWrapper::insertBefore($item, $existingItem)
$this

Insert one Inputfield before one that’s already there.

 
InputfieldWrapper::new(string $typeName)
Inputfield InputfieldSelect InputfieldWrapper

Create a new Inputfield, add it to this InputfieldWrapper, and return the new Inputfield

InputfieldWrapper::populateValues($data)
array

Populate values for all Inputfields in this wrapper from the given $data object or array.

 
InputfieldWrapper::prepend(Inputfield $item)
$this

Prepend an Inputfield to this instance’s children.

 
InputfieldWrapper::remove($key)
$this

Remove an Inputfield from this instance’s children.

 

Retrieval and traversal

NameReturnSummary 
InputfieldWrapper::child()
Inputfield null

Find an Inputfield below this one that has the given name

 
InputfieldWrapper::children()
InputfieldsArray

Return all children Inputfield objects


Can also be used as property: InputfieldWrapper::children
 
InputfieldWrapper::count()
int

Return the quantity of children present

 
InputfieldWrapper::find(string $selector)
InputfieldsArray

Find all children Inputfields matching a selector string

 
InputfieldWrapper::get(string $key)
Inputfield mixed

Get a child Inputfield having a name attribute matching the given $key.

 
InputfieldWrapper::getAll()
InputfieldsArray

Get all Inputfields below this recursively in a flat InputfieldWrapper (children, and their children, etc.)

 
InputfieldWrapper::getByAttr(string $attrName, string $attrValue)
Inputfield InputfieldWrapper null

Given an attribute name and value, return the first matching Inputfield or null if not found

 
InputfieldWrapper::getByField($field)
Inputfield InputfieldWrapper null

Get Inputfield by Field (hasField)

 
InputfieldWrapper::getByName(string $name)
Inputfield InputfieldWrapper null

Shorter alias of getChildByName()

 
InputfieldWrapper::getByProperty(string $property, mixed $value)
Inputfield InputfieldWrapper null array

Get Inputfield by some other non-attribute property or setting

 
InputfieldWrapper::getChildByName(string $name)
Inputfield InputfieldWrapper null

Given an Inputfield name, return the child Inputfield or NULL if not found.

 
InputfieldWrapper::getIterator()
InputfieldsArray

Enables foreach() of the children of this class

 
InputfieldWrapper::isEmpty()
bool

Returns true if all children are empty, or false if one or more is populated

 

For hooks

These methods are only useful for hooking and should not be called directly.

Errors

NameReturnSummary 
InputfieldWrapper::getErrorInputfields()
array Inputfield

Get Inputfield objects that have errors

 
InputfieldWrapper::getErrors()
array

Return an array of errors that occurred on any of the children during input processing.

 

Properties

Access any common Inputfield type class name from an InputfieldWrapper and it will return a new instance of that Inputfield, i.e. $f = $inputfields->InputfieldText; Below are several examples.

NameReturnSummary 
InputfieldWrapper::InputfieldAsmSelect InputfieldAsmSelect Create new asmSelect Inputfield  
InputfieldWrapper::InputfieldButton InputfieldButton Create new button Inputfield  
InputfieldWrapper::InputfieldCKEditor InputfieldCKEditor Create new CKEditor Inputfield  
InputfieldWrapper::InputfieldCheckbox InputfieldCheckbox Create new checkbox Inputfield  
InputfieldWrapper::InputfieldCheckboxes InputfieldCheckboxes Create new checkboxes Inputfield  
InputfieldWrapper::InputfieldDatetime InputfieldDatetime Create new date/time Inputfield  
InputfieldWrapper::InputfieldEmail InputfieldEmail Create new email Inputfield  
InputfieldWrapper::InputfieldFieldset InputfieldFieldset Create new Fieldset InputfieldWrapper  
InputfieldWrapper::InputfieldFile InputfieldFile Create new file Inputfield  
InputfieldWrapper::InputfieldFloat InputfieldFloat Create new float Inputfield  
InputfieldWrapper::InputfieldForm InputfieldForm Create new form InputfieldWrapper  
InputfieldWrapper::InputfieldHidden InputfieldHidden Create new hidden Inputfield  
InputfieldWrapper::InputfieldIcon InputfieldIcon Create new icon Inputfield  
InputfieldWrapper::InputfieldImage InputfieldImage Create new image Inputfield  
InputfieldWrapper::InputfieldInteger InputfieldInteger Create new integer Inputfield  
InputfieldWrapper::InputfieldMarkup InputfieldMarkup Create new markup Inputfield  
InputfieldWrapper::InputfieldPage InputfieldPage Create new Page selection Inputfield  
InputfieldWrapper::InputfieldPageAutocomplete InputfieldPageAutocomplete Create new Page selection autocomplete Inputfield  
InputfieldWrapper::InputfieldPageListSelect InputfieldPageListSelect Create new PageListSelect Inputfield  
InputfieldWrapper::InputfieldPageListSelectMultiple InputfieldPageListSelectMultiple Create new multiple PageListSelect Inputfield  
InputfieldWrapper::InputfieldRadios InputfieldRadios Create new radio buttons Inputfield  
InputfieldWrapper::InputfieldSelect InputfieldSelect Create new <select> Inputfield  
InputfieldWrapper::InputfieldSelectMultiple InputfieldSelectMultiple Create new <select multiple> Inputfield  
InputfieldWrapper::InputfieldSubmit InputfieldSubmit Create new submit button Inputfield  
InputfieldWrapper::InputfieldText InputfieldText Create new single-line text Inputfield  
InputfieldWrapper::InputfieldTextTags InputfieldTextTags Create new text tags Inputfield  
InputfieldWrapper::InputfieldTextarea InputfieldTextarea Create new multi-line <textarea> Inputfield  
InputfieldWrapper::InputfieldToggle InputfieldToggle Create new toggle Inputfield  
InputfieldWrapper::InputfieldURL InputfieldURL Create new URL Inputfield  
InputfieldWrapper::InputfieldWrapper InputfieldWrapper Create new generic InputfieldWrapper  

Additional methods and properties

In addition to the methods and properties above, InputfieldWrapper also inherits the methods and properties of these classes:

API reference based on ProcessWire core version 3.0.266