InputfieldSubmit

Form submit button

Renders a <button type="submit"> element. Extends [[Inputfield]].

$f = $modules->get('InputfieldSubmit');
$f->name = 'save';
$f->value = 'Save Changes';
$f->showInHeader();
$form->add($f);

After processInput(), check whether the button was clicked via submitValue:

if($f->submitValue !== false) {
 // this button was clicked
}

See [[Inputfield]] for the shared Inputfield API (labels, collapsed states, rendering, processing, etc.).

Properties
PropertyTypeDefaultDescription
valuestring'Submit'Button label text and the value submitted when clicked
textstring''Label text (overrides value for display; value is still submitted)
htmlstring''Inner HTML (overrides text and value for display; 3.0.134+
iconstring''Icon name (e.g. 'save') prepended to the button label
textClassstring'ui-button-text'CSS class for the inner <span> wrapping the label
headerboolfalseAlso render the button in the page header
secondaryboolfalseRender as a secondary (slightly faded) button
smallboolfalseRender as a smaller button
submitValuestring\|falsefalseRead-only: submitted value if clicked, false if not (after processInput())
dropdownInputNamestring'_action_value'Name of the hidden <input> that receives the selected dropdown item value
dropdownSubmitbooltrueWhen true, the selected dropdown value also becomes the submit button's value
dropdownRequiredboolfalseWhen true, clicking the button without a dropdown selection opens the dropdown instead of submitting 3.0.180+
Fluent methods

These methods return $this for chaining and are equivalent to setting the same-named properties directly:

$f->showInHeader(); // also render button in the page header
$f->setSecondary(); // make button secondary (slightly faded)
$f->setSmall(); // make button smaller

All three accept an optional bool argument (defaults to true); pass false to undo.

Dropdown actions

A dropdown can be appended to a submit button with additional actions. Each item is either a link or a value that is submitted with the form.

// submits _action_value='save_and_close' when selected
$f->addActionValue('save_and_close', 'Save and Close', 'times-circle');
// navigates directly to the URL when selected
$f->addActionLink('/admin/page/list/', 'Cancel', 'ban');
addActionValue($value, $label, $icon = '')
Adds a dropdown item that populates a hidden input before submitting. Icon is a Font Awesome name without the fa- prefix.
addActionLink($url, $label, $icon = '')
Adds a dropdown item that navigates to $url when selected.

After processInput(), $f->submitValue holds the value that was submitted — either the main button's value or the selected dropdown item's value.

Dropdown properties

By default (dropdownSubmit = true), the selected dropdown item's value becomes the submit button's submitted value (i.e. it appears in $_POST[$f->name]) and is also copied to $_POST[$f->dropdownInputName] (default '_action_value'). Set dropdownSubmit = false to only populate the hidden input, leaving the button's own submitted value unaffected:

$f->dropdownSubmit = false;
// Now: $_POST['submit'] == 'Save Changes' (the button value, always)
// $_POST['_action_value'] == 'save_and_close' (the dropdown choice)

Change dropdownInputName if '_action_value' conflicts with another field:

$f->dropdownInputName = 'my_action';
// Selected item value will be in $_POST['my_action']

Require a dropdown selection before the form can be submitted:

$f->dropdownRequired = true;
// Clicking the button without selecting a dropdown item opens the dropdown instead
Multiple submit buttons

When a form has more than one submit button, give each a unique name:

$save = $modules->get('InputfieldSubmit');
$save->name = 'btn_save';
$save->value = 'Save';
$delete = $modules->get('InputfieldSubmit');
$delete->name = 'btn_delete';
$delete->value = 'Delete';
$delete->setSecondary();

After processInput(), check submitValue on each to see which was clicked.

Notes
  • submitValue is false before processInput(). After, it is a string (possibly empty) when the button was clicked, and false when it was not.
  • The name attribute defaults to 'submit'. Always change it when using multiple submit buttons in one form.
  • Source file: wire/modules/Inputfield/InputfieldSubmit/InputfieldSubmit.module
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 InputfieldSubmit class also inherits all the methods and properties of: Inputfield, WireData and Wire.

Show class? Show args? Only hookable?

Common

NameReturnSummary
InputfieldSubmit::addActionLink(string $url, string $label)
None

Add a dropdown action item that links to a URL

InputfieldSubmit::addActionValue(string $value, string $label)
None

Add a dropdown action item that populates a new 'value' for the submit button

InputfieldSubmit::get($key)
None
InputfieldSubmit::processInput(WireInputData $input)
$this

Process input

InputfieldSubmit::render()
string

Render the button

InputfieldSubmit::renderReady()
bool

Render ready

InputfieldSubmit::set($key, $value)
None
InputfieldSubmit::setAttribute($key, $value)
None
InputfieldSubmit::setSecondary()
$this

Make this button secondary? (slightly faded)

InputfieldSubmit::setSmall()
$this

Make this button small?

InputfieldSubmit::showInHeader()
$this

Show another copy of this button in the header?

Properties

NameReturnSummary
InputfieldSubmit::header bool Whether or not button will also appear in header .
DEFAULT: false
InputfieldSubmit::html string Button inner HTML label 3.0.134
DEFAULT: ''
InputfieldSubmit::secondary bool Whether or not button is secondary .
DEFAULT: false
InputfieldSubmit::small bool Whether or not button should be small, where supported .
DEFAULT: false
InputfieldSubmit::submitValue string false Value that was submitted if clicked 3.0.134
DEFAULT: false
InputfieldSubmit::text string Button inner TEXT label, if $html not provided. 3.0.134
DEFAULT: ''
InputfieldSubmit::textClass string Class applied to span for inner html/text, omitted if blank 3.0.134
DEFAULT: 'ui-button-text'
InputfieldSubmit::value string Button value attribute and inner TEXT label, if $text it provided
DEFAULT: 'Submit'

Additional methods and properties

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

API reference based on ProcessWire core version 3.0.267

AltStyle によって変換されたページ (->オリジナル) /