Inputfield class

Inputfield is the base class for modules that collect user input for fields.

// Create an Inputfield
$inputfield = $modules->get('InputfieldText');
$inputfield->label = 'Your Name';
$inputfield->attr('name', 'your_name');
$inputfield->attr('value', 'Roderigo');
// Add to a $form (InputfieldForm or InputfieldWrapper)
$form->add($inputfield); 

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

Show class?             Show args?        

Attribute methods

NameReturnSummary 
Inputfield::addClass($class)
$thisAdd a class or classes to this Inputfield (or a wrapping element) 
Inputfield::attr($key)
Inputfield array string int object floatGet or set an attribute (or multiple attributes) 
Inputfield::class()
string InputfieldGet class attribute or add a class to the class attribute. @since 3.0.110
Can also be used as property: Inputfield::class
Inputfield::has(string $key)
boolDoes this Inputfield have the requested property or attribute? 
Inputfield::hasClass($class)
boolDoes this Inputfield have the given class name (or names)? 
Inputfield::id()
string InputfieldGet or set the id attribute. @since 3.0.110
Can also be used as property: Inputfield::id
Inputfield::isEmpty()
boolIs this Inputfield empty? (Value attribute reflects an empty state) 
Inputfield::name()
string InputfieldGet or set the name attribute. @since 3.0.110
Can also be used as property: Inputfield::name
Inputfield::removeAttr(string $key)
$thisRemove an attribute 
Inputfield::removeClass($class)
$thisRemove the given class (or classes) from this Inputfield 
Inputfield::wrapAttr()
Inputfield string array nullGet or set attribute for the element wrapping this Inputfield 

Attribute properties

These properties are retrieved or manipulated via the attribute methods above.

NameReturnSummary 
Inputfield::value mixed HTML 'value' attribute for the Inputfield.  

Settings

NameReturnSummary 
Inputfield::get(string $key)
mixed nullGet a property or attribute from the Inputfield 
Inputfield::getSetting(string $key)
mixedGets a setting (or API variable) from the Inputfield, while ignoring attributes. 
Inputfield::has(string $key)
boolDoes this Inputfield have the requested property or attribute? 
Inputfield::set(string $key, mixed $value)
Inputfield WireDataSet a property or attribute to the Inputfield 

Traversal

NameReturnSummary 
Inputfield::getForm()
InputfieldForm nullGet the InputfieldForm element that contains this field or null if not yet defined 
Inputfield::getParent()
InputfieldWrapper nullGet this Inputfield’s parent InputfieldWrapper, or NULL if it doesn’t have one. 
Inputfield::getParents()
arrayGet array of all parents of this Inputfield. 
Inputfield::getRootParent()
InputfieldForm InputfieldWrapper nullGet the root parent InputfieldWrapper element (farthest parent, commonly InputfieldForm) 
Inputfield::parent()
null Inputfield InputfieldWrapperGet or set parent of Inputfield 
Inputfield::parents()
arrayGet array of all parents of this Inputfield 
Inputfield::setParent(InputfieldWrapper $parent)
$thisSet the parent (InputfieldWrapper) of this Inputfield. 

Labels

NameReturnSummary 
Inputfield::appendMarkup()
string InputfieldGet or set the 'appendMarkup' property via method. @since 3.0.110
Can also be used as property: Inputfield::appendMarkup
Inputfield::description()
string InputfieldGet or set the 'description' property via method. @since 3.0.110
Can also be used as property: Inputfield::description
Inputfield::head()
string InputfieldGet or set the 'head' property via method. @since 3.0.110
Inputfield::icon()
string InputfieldGet or set the 'icon' property via method. @since 3.0.110
Can also be used as property: Inputfield::icon
Inputfield::label()
string InputfieldGet or set the 'label' property via method. @since 3.0.110
Can also be used as property: Inputfield::label
Inputfield::notes()
string InputfieldGet or set the 'notes' property via method. @since 3.0.110
Can also be used as property: Inputfield::notes
Inputfield::prependMarkup()
string InputfieldGet or set the 'prependMarkup' property via method. @since 3.0.110
Can also be used as property: Inputfield::prependMarkup
Inputfield::requiredLabel()
string InputfieldGet or set the 'requiredLabel' property via method. @since 3.0.110
Can also be used as property: Inputfield::requiredLabel

Appearance

NameReturnSummary 
Inputfield::collapsed()
int InputfieldGet or set collapsed property via method. @since 3.0.110
Can also be used as property: Inputfield::collapsed
Inputfield::columnWidth()
int InputfieldGet or set columnWidth property via method. @since 3.0.110
Can also be used as property: Inputfield::columnWidth
Inputfield::showIf()
string InputfieldGet or set showIf selector property via method. @since 3.0.110
Can also be used as property: Inputfield::showIf
Inputfield::skipLabel()
int InputfieldGet or set the skipLabel constant property via method. @since 3.0.110
Can also be used as property: Inputfield::skipLabel

Behavior

NameReturnSummary 
Inputfield::required()
string InputfieldGet or set required state. @since 3.0.110
Can also be used as property: Inputfield::required
Inputfield::requiredIf()
string InputfieldGet or set required-if selector. @since 3.0.110
Can also be used as property: Inputfield::requiredIf
Inputfield::useLanguages bool null When multi-language support active, can be set to true to make it provide inputs for each language, where supported (default=false).  

Other

NameReturnSummary 
Inputfield::contentClass()
string InputfieldGet content class attribute or add a class to it. @since 3.0.110
Can also be used as property: Inputfield::contentClass
Inputfield::hasField null Field The Field object associated with this Inputfield, or null when not applicable or not known.  
Inputfield::hasFieldtype null bool Fieldtype The Fieldtype using this Inputfield, or boolean false when known not to have a Fieldtype, or null when not known.  
Inputfield::hasPage null Page The Page object associated with this Inputfield, or null when not applicable or not known.  
Inputfield::headerClass()
string InputfieldGet header class attribute or add a class to it. @since 3.0.110
Can also be used as property: Inputfield::headerClass
Inputfield::wrapClass()
string InputfieldGet wrapper class attribute or add a class to it. @since 3.0.110
Can also be used as property: Inputfield::wrapClass

Output

NameReturnSummary 
Inputfield::entityEncode(string $str)
stringEntity encode a string with optional Markdown support. 
Inputfield::entityEncodeLabel null bool int Set to boolean false to specifically disable entity encoding of field header/label (default=true).  
Inputfield::entityEncodeText null bool Set to boolean false to specifically disable entity encoding for other text: description, notes, etc. (default=true).  
Inputfield::render()
stringRender the HTML input element(s) markup, ready for insertion in an HTML form.
Inputfield::renderReady()
boolMethod called right before Inputfield markup is rendered, so that any dependencies can be loaded as well. 
Inputfield::renderValue()
stringRender just the value (not input) in text/markup for presentation purposes.
Inputfield::renderValueFlags int Options that can be applied to renderValue mode, see "renderValue" constants (default=0).  
Inputfield::textFormat int null Text format to use for description/notes text in Inputfield (see textFormat constants)  

Input

NameReturnSummary 
Inputfield::processInput(WireInputData $input)
$thisProcess input for this Inputfield directly from the POST (or GET) variables

States

NameReturnSummary 
Inputfield::editable()
boolGet or set editable state for this Inputfield 
Inputfield::error(string $text)
mixedRecord an error for this Inputfield 
Inputfield::getErrors()
arrayReturn array of strings containing errors that occurred during input processing 

Module

Methods primarily of interest during module development.

NameReturnSummary 
Inputfield::getConfigAllowContext(Field $field)
arrayReturn a list of config property names allowed for fieldgroup/template context
Inputfield::getConfigArray()
arrayAlternative method for configuration that allows for array definition
Inputfield::getConfigInputfields()
InputfieldWrapperGet any custom configuration fields for this Inputfield
Inputfield::init()
(nothing)Per the Module interface, init() is called after any configuration data has been populated to the Inputfield, but before render. 
Inputfield::install()
(nothing)Per the Module interface, this method is called when this Inputfield is installed
Inputfield::uninstall()
(nothing)Per the Module interface, uninstall() is called when this Inputfield is uninstalled

Common

NameReturnSummary 
Inputfield::renderReadyHook()
(nothing)Hookable version of renderReady(), not called unless 'renderReadyHook' is hooked
Inputfield::val()
mixedShortcut for getting or setting “value” attribute 

Collapsed constants

Constants allowed for the Inputfield::collapsed property.

NameReturnSummary 
Inputfield::collapsedBlank const2Collapsed only when blank 
Inputfield::collapsedBlankAjax const11Collapsed only when blank, and dynamically loaded by AJAX when opened 
Inputfield::collapsedHidden const4Hidden, not rendered in the form at all 
Inputfield::collapsedNever const9Never collapsed, and not collapsible 
Inputfield::collapsedNo const0Not collapsed (display as "open", default) 
Inputfield::collapsedNoLocked const7Not collapsed, value visible but not editable 
Inputfield::collapsedPopulated const5Collapsed only when populated 
Inputfield::collapsedYes const1Collapsed unless opened 
Inputfield::collapsedYesAjax const10Collapsed and dynamically loaded by AJAX when opened 
Inputfield::collapsedYesLocked const8Collapsed unless opened (value becomes visible but not editable) 

SkipLabel constants

Constants allowed for the Inputfield::skipLabel property.

NameReturnSummary 
Inputfield::skipLabelBlank const4Skip rendering of the label when it is blank 
Inputfield::skipLabelFor consttrueDon't use a "for" attribute with the <label> 
Inputfield::skipLabelHeader const2Don't use a label header element at all (basically, skip the label) 
Inputfield::skipLabelNo constfalseDon't skip the label (default) 

TextFormat constants

Constants for formats allowed in description, notes, label.

NameReturnSummary 
Inputfield::textFormatBasic const4Only allow basic/inline markdown, and no HTML (default) 
Inputfield::textFormatMarkdown const8Full markdown support with HTML also allowed 
Inputfield::textFormatNone const2Plain text: no type of markdown or HTML allowed 

RenderValue constants

Options for Inputfield::renderValueFlags property, applicable Inputfield::renderValue() method call.

NameReturnSummary 
Inputfield::renderValueFirst const8If there are multiple items, only render the first (where supported by the Inputfield). 
Inputfield::renderValueMinimal const2Render only the minimum output when in "renderValue" mode. 
Inputfield::renderValueNoWrap const4Indicates a parent InputfieldWrapper is not required when rendering value. 

Additional methods and properties

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

API reference based on ProcessWire core version 3.0.135

Twitter updates

  • New post: Version 3.0.135 of ProcessWire on the dev branch focuses on some .htaccess updates, adds clarity to debug mode, and improves upon the installer— More
    5 July 2019
  • ProcessWire 3.0.133 adds a useful new Page::meta() method for a new type of page-specific persistent data storage, adds the ability for users to create their own bookmarks in Lister, and has a handy and time saving update for the asmSelect input type— More
    14 June 2019
  • New post: This week we’ll take a look at 3 different WEBP image strategies that you can use in ProcessWire 3.0.132+. Then we’ll dive into a major update for the Google Client API module, and finish up by outlining some useful new updates in FormBuilder— More
    31 May 2019

Latest news

  • ProcessWire Weekly #270
    This week in the 270th issue of ProcessWire Weekly we're going to cover the SearchEngine module, feature some recent support forum highlights, and introduce a brand new site of the week. Read on!
    Weekly.pw / 13 July 2019
  • ProcessWire 3.0.135 core updates
    Version 3.0.135 of ProcessWire on the dev branch focuses on .htaccess updates, adds additional layers of security, adds clarity to debug mode, and improves upon the installer.
    Blog / 3 July 2019
  • Subscribe to weekly ProcessWire news

“ProcessWire is like a breath of fresh air. So powerful yet simple to build with and customise, and web editors love it too.” —Margaret Chatwin, Web developer