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

Settings

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

Traversal

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

Labels

NameReturnSummary 
appendMarkup()
string InputfieldGet or set the 'appendMarkup' property via method. @since 3.0.110
Can also be used as property: appendMarkup
description()
string InputfieldGet or set the 'description' property via method. @since 3.0.110
Can also be used as property: description
detail string Optional text details that appear under notes. @since 3.0.140  
head()
string InputfieldGet or set the 'head' property via method. @since 3.0.110
icon()
string InputfieldGet or set the 'icon' property via method. @since 3.0.110
Can also be used as property: icon
label()
string InputfieldGet or set the 'label' property via method. @since 3.0.110
Can also be used as property: label
notes()
string InputfieldGet or set the 'notes' property via method. @since 3.0.110
Can also be used as property: notes
prependMarkup()
string InputfieldGet or set the 'prependMarkup' property via method. @since 3.0.110
Can also be used as property: prependMarkup
requiredLabel()
string InputfieldGet or set the 'requiredLabel' property via method. @since 3.0.110
Can also be used as property: requiredLabel
tabLabel string Label for tab if Inputfield rendered in its own tab via collapsedTab* setting. @since 3.0.201  

Appearance

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

Uikit

Settings for Inputfields recognized and used by AdminThemeUikit.

NameReturnSummary 
themeBlank bool Makes <input> element display with no minimal container / no border when true.  
themeBorder string Border style for Inputfield, one of 'none', 'card', 'hide' or 'line'.  
themeColor string Color theme for Inputfield, one of 'primary', 'secondary', 'warning', 'danger', 'success', 'highlight', 'none'.  
themeInputSize string Input size height/font within Inputfield, one of 's', 'm', or 'l'.  
themeInputWidth string Input width for text-type inputs, one of 'xs', 's', 'm', 'l', or 'f' (for full-width).  
themeOffset bool string Offset/margin for Inputfield, one of 's', 'm', or 'l'.  

Behavior

NameReturnSummary 
required()
string InputfieldGet or set required state. @since 3.0.110
Can also be used as property: required
requiredAttr int bool null Use HTML5 “required” attribute when used by Inputfield and $required is true? Default=null.  
requiredIf()
string InputfieldGet or set required-if selector. @since 3.0.110
Can also be used as property: requiredIf
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 
contentClass()
string InputfieldGet content class attribute or add a class to it. @since 3.0.110
Can also be used as property: contentClass
hasField null Field The Field object associated with this Inputfield, or null when not applicable or not known.  
hasFieldtype null bool Fieldtype The Fieldtype using this Inputfield, or boolean false when known not to have a Fieldtype, or null when not known.  
hasInputfield null Inputfield If this Inputfield is owned/managed by another (other than parent/child relationship), it may be set here. @since 3.0.176  
hasPage null Page The Page object associated with this Inputfield, or null when not applicable or not known.  
headerClass()
string InputfieldGet header class attribute or add a class to it. @since 3.0.110
Can also be used as property: headerClass
wrapClass()
string InputfieldGet wrapper class attribute or add a class to it. @since 3.0.110
Can also be used as property: wrapClass

Output

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

Input

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

States

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

Module

Methods primarily of interest during module development.

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

Languages

NameReturnSummary 
getLanguageValue($language)
string mixedGet language value for Inputfield that supports it. Requires LanguageSupport module. $language can be Language, id (int) or name (string). @since 3.0.238
setLanguageValue($language, $value)
(nothing)Set language value for Inputfield that supports it. Requires LanguageSupport module. $language can be Language, id (int) or name (string). @since 3.0.238
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).  

Advanced

NameReturnSummary 
footerMarkup string null Optional markup to add to the '.Inputfield' container, after '.InputfieldContent'. @since 3.0.241  

Collapsed constants

Constants allowed for the collapsed property.

NameReturnSummary 
collapsedBlank const2Collapsed only when blank 
collapsedBlankAjax const11Collapsed only when blank, and dynamically loaded by AJAX when opened 
collapsedBlankLocked const7Collapsed when blank, value visible but not editable 
collapsedHidden const4Hidden, not rendered in the form at all 
collapsedNever const9Never collapsed, and not collapsible 
collapsedNo const0Not collapsed (display as "open", default) 
collapsedNoLocked const6Not collapsed, value visible but not editable 
collapsedPopulated const5Collapsed only when populated 
collapsedTab const20Collapsed into a separate tab @since 3.0.201 
collapsedTabAjax const21Collapsed into a separate tab and AJAX loaded @since 3.0.201 
collapsedTabLocked const22Collapsed into a separate tab and locked (not editable) @since 3.0.201 
collapsedYes const1Collapsed unless opened 
collapsedYesAjax const10Collapsed and dynamically loaded by AJAX when opened 
collapsedYesLocked const8Collapsed unless opened (value becomes visible but not editable) 

SkipLabel constants

Constants allowed for the skipLabel property.

NameReturnSummary 
skipLabelBlank const4Skip rendering of the label when it is blank 
skipLabelFor consttrueDon't use a "for" attribute with the <label> 
skipLabelHeader const2Don't show a visible header (likewise, do not show the label) 
skipLabelMarkup const8Do not render any markup for the header/label at all @since 3.0.139 
skipLabelNo constfalseDon't skip the label (default) 

TextFormat constants

Constants for formats allowed in description, notes, label.

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

Render constants

NameReturnSummary 
renderFirst const1Render flags: place first in render 
renderLast const2Render flags: place last in render 

RenderValue constants

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

NameReturnSummary 
renderValueFirst const8If there are multiple items, only render the first (where supported by the Inputfield). 
renderValueMinimal const2Render only the minimum output when in "renderValue" mode. 
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.244

“We were really happy to build our new portfolio website on ProcessWire! We wanted something that gave us plenty of control on the back-end, without any bloat on the front end - just a nice, easy to access API for all our content that left us free to design and build however we liked.” —Castus, web design agency in Sheffield, UK