MediaWiki  master
HTMLForm Class Reference

Object handling generic submission, CSRF protection, layout and other logic for UI forms in a reusable manner. More...

Inheritance diagram for HTMLForm:
Collaboration diagram for HTMLForm:

Public Member Functions

 __construct ( $descriptor, IContextSource $context, $messagePrefix='')
 Build a new HTMLForm from an array of field attributes. More...
 
 addButton ( $data)
 Add a button to the form. More...
 
 addFields ( $descriptor)
 Add fields to the form. More...
 
 addFooterHtml ( $html, $section=null)
 Add footer HTML, inside the form. More...
 
 addFooterText ( $msg, $section=null)
 Add footer text, inside the form. More...
 
 addHeaderHtml ( $html, $section=null)
 Add HTML to the header, inside the form. More...
 
 addHeaderText ( $msg, $section=null)
 Add HTML to the header, inside the form. More...
 
 addHiddenField ( $name, $value, array $attribs=[])
 Add a hidden field to the output. More...
 
 addHiddenFields (array $fields)
 Add an array of hidden fields to the output. More...
 
 addPostHtml ( $html)
 Add HTML to the end of the display. More...
 
 addPostText ( $msg)
 Add text to the end of the display. More...
 
 addPreHtml ( $html)
 Add HTML to introductory message. More...
 
 addPreText ( $msg)
 Add HTML to introductory message. More...
 
 displayForm ( $submitResult)
 Display the form (sending to the context's OutputPage object), with an appropriate error message or stack of messages, and any validation errors, etc. More...
 
 displaySection ( $fields, $sectionName='', $fieldsetIDPrefix='', &$hasUserVisibleFields=false)
 
 filterDataForSubmit ( $data)
 Overload this if you want to apply special filtration routines to the form as a whole, after it's submitted but before it's processed. More...
 
 formatErrors ( $errors)
 Format a stack of error messages into a single HTML string. More...
 
 getAction ()
 Get the value for the action attribute of the form. More...
 
 getBody ()
 Get the whole body of the form. More...
 
 getButtons ()
 Get the submit and (potentially) reset buttons. More...
 
 getDisplayFormat ()
 Getter for displayFormat. More...
 
 getErrorsOrWarnings ( $elements, $elementsType)
 Returns a formatted list of errors or warnings from the given elements. More...
 
 getField ( $fieldname)
 
 getFooterHtml ( $section=null)
 Get footer HTML. More...
 
 getFooterText ( $section=null)
 Get footer text. More...
 
 getHeaderHtml ( $section=null)
 Get header HTML. More...
 
 getHeaderText ( $section=null)
 Get header text. More...
 
 getHiddenFields ()
 Get the hidden fields that should go inside the form. More...
 
 getHTML ( $submitResult)
 Returns the raw HTML generated by the form. More...
 
 getLegend ( $key)
 Get a string to go in the "<legend>" of a section fieldset. More...
 
 getMethod ()
 
 getPostHtml ()
 Get HTML at the end of the display. More...
 
 getPreHtml ()
 Get the introductory message HTML. More...
 
 getPreText ()
 Get the introductory message HTML. More...
 
 getSubmitText ()
 Get the text for the submit button, either customised or a default. More...
 
 getTitle ()
 
 hasField ( $fieldname)
 
 loadData ()
 
 needsJSForHtml5FormValidation ()
 Whether this form, with its current fields, requires the user agent to have JavaScript enabled for the client-side HTML5 form validation to work correctly. More...
 
 prepareForm ()
 Prepare form for submission. More...
 
 setAction ( $action)
 Set the value for the action attribute of the form. More...
 
 setAutocomplete ( $autocomplete)
 Set the value for the autocomplete attribute of the form. More...
 
 setCancelTarget ( $target)
 Sets the target where the user is redirected to after clicking cancel. More...
 
 setCollapsibleOptions ( $collapsedByDefault=false)
 Enable collapsible mode, and set whether the form is collapsed by default. More...
 
 setDisplayFormat ( $format)
 Set format in which to display the form. More...
 
 setFooterHtml ( $html, $section=null)
 Set footer HTML, inside the form. More...
 
 setFooterText ( $msg, $section=null)
 Set footer text, inside the form. More...
 
 setFormIdentifier ( $ident)
 Set an internal identifier for this form. More...
 
 setHeaderHtml ( $html, $section=null)
 Set header HTML, inside the form. More...
 
 setHeaderText ( $msg, $section=null)
 Set header text, inside the form. More...
 
 setId ( $id)
 
 setIntro ( $msg)
 Set the introductory message, overwriting any existing message. More...
 
 setMessagePrefix ( $p)
 Set the prefix for various default messages. More...
 
 setMethod ( $method='post')
 Set the method used to submit the form. More...
 
 setName ( $name)
 
 setPostHtml ( $html)
 Set HTML at the end of the display. More...
 
 setPostText ( $msg)
 Set text at the end of the display. More...
 
 setPreHtml ( $html)
 Set the introductory message HTML, overwriting any existing message. More...
 
 setPreText ( $msg)
 Set the introductory message HTML, overwriting any existing message. More...
 
 setSubmitCallback ( $cb)
 Set a callback to a function to do something with the form once it's been successfully validated. More...
 
 setSubmitDestructive ()
 Identify that the submit button in the form has a destructive action. More...
 
 setSubmitID ( $t)
 Set the id for the submit button. More...
 
 setSubmitName ( $name)
 
 setSubmitText ( $t)
 Set the text for the submit button. More...
 
 setSubmitTextMsg ( $msg)
 Set the text for the submit button to a message. More...
 
 setSubmitTooltip ( $name)
 
 setTableId ( $id)
 Set the id of the \<table\> or outermost \<div\> element. More...
 
 setTitle ( $t)
 Set the title for form submission. More...
 
 setTokenSalt ( $salt)
 Set the salt for the edit token. More...
 
 setValidationErrorMessage ( $msg)
 Set a message to display on a validation error. More...
 
 setWrapperAttributes ( $attributes)
 For internal use only. More...
 
 setWrapperLegend ( $legend)
 Prompt the whole form to be wrapped in a "<fieldset>", with this text as its "<legend>" element. More...
 
 setWrapperLegendMsg ( $msg)
 Prompt the whole form to be wrapped in a "<fieldset>", with this message as its "<legend>" element. More...
 
 show ()
 The here's-one-I-made-earlier option: do the submission if posted, or display the form with or without funky validation errors. More...
 
 showAlways ()
 Same as self::show with the difference, that the form will be added to the output, no matter, if the validation was good or not. More...
 
 showCancel ( $show=true)
 Show a cancel button (or prevent it). More...
 
 suppressDefaultSubmit ( $suppressSubmit=true)
 Stop a default submit button being shown for this form. More...
 
 suppressReset ( $suppressReset=true)
 Stop a reset button being shown for this form. More...
 
 tryAuthorizedSubmit ()
 Try submitting, with edit token check first. More...
 
 trySubmit ()
 Validate all the fields, and call the submission callback function if everything is kosher. More...
 
 wasSubmitted ()
 Test whether the form was considered to have been submitted or not, i.e. More...
 
 wrapForm ( $html)
 Wrap the form innards in an actual "<form>" element. More...
 
- Public Member Functions inherited from ContextSource
 canUseWikiPage ()
 Check whether a WikiPage object can be get with getWikiPage(). More...
 
 exportSession ()
 Export the resolved user IP, HTTP headers, user ID, and session ID. More...
 
 getActionName ()
 Get the action name for the current web request. More...
 
 getAuthority ()
 
 getConfig ()
 
 getContext ()
 Get the base IContextSource object. More...
 
 getCsrfTokenSet ()
 Get a repository to obtain and match CSRF tokens. More...
 
 getLanguage ()
 
 getOutput ()
 
 getRequest ()
 
 getSkin ()
 
 getStats ()
 
 getTiming ()
 
 getUser ()
 
 getWikiPage ()
 Get the WikiPage object. More...
 
 msg ( $key,... $params)
 Get a Message object with context set Parameters are the same as wfMessage() More...
 
 setContext (IContextSource $context)
 

Static Public Member Functions

static factory ( $displayFormat, $descriptor, IContextSource $context, $messagePrefix='')
 Construct a HTMLForm object for given display type. More...
 
static getClassFromDescriptor ( $fieldname, &$descriptor)
 Get the HTMLFormField subclass for this descriptor. More...
 
static loadInputFromParameters ( $fieldname, $descriptor, HTMLForm $parent=null)
 Initialise a new Object for the field. More...
 

Public Attributes

 $mFieldData
 

Static Public Attributes

static string[] $typeMappings
 A mapping of 'type' inputs onto standard HTMLFormField subclasses. More...
 

Protected Member Functions

 formatSection (array $fieldsHtml, $sectionName, $anyFieldHasLabel)
 Put a form section together from the individual fields' HTML, merging it and wrapping. More...
 
 getCancelTargetURL ()
 
 getFormAttributes ()
 Get HTML attributes for the <form> tag. More...
 
 getMessage ( $value)
 Turns a *-message parameter (which could be a MessageSpecifier, or a message name, or a name + parameters array) into a Message. More...
 
 loadFieldData ()
 Load data of form fields from the request. More...
 
 wrapFieldSetSection ( $legend, $section, $attributes, $isRoot)
 Wraps the given $section into an user-visible fieldset. More...
 

Protected Attributes

array $availableDisplayFormats
 Available formats in which to display the form. More...
 
array $availableSubclassDisplayFormats
 Available formats in which to display the form. More...
 
string $displayFormat = 'table'
 Format in which to display form. More...
 
bool string $mAction = false
 Form action URL. More...
 
string null $mAutocomplete = null
 Form attribute autocomplete. More...
 
array[] $mButtons = []
 
 $mCancelTarget
 
bool $mCollapsed = false
 Whether the form is collapsed by default. More...
 
bool $mCollapsible = false
 Whether the form can be collapsed. More...
 
 $mFieldTree = []
 
HTMLFormField[] $mFlatFields = []
 
 $mFooter = ''
 
 $mFormIdentifier
 
 $mHeader = ''
 
array[] $mHiddenFields = []
 
 $mId
 
 $mMessagePrefix
 
 $mMethod = 'post'
 
 $mName
 
 $mPost = ''
 
 $mPre = ''
 
 $mSectionFooters = []
 
 $mSectionHeaders = []
 
 $mShowCancel = false
 
 $mShowReset = false
 
 $mShowSubmit = true
 
 $mSubmitCallback
 
string[] $mSubmitFlags = [ 'primary', 'progressive' ]
 
 $mSubmitID
 
 $mSubmitName
 
 $mSubmitText
 
 $mSubmitTooltip
 
bool $mSubSectionBeforeFields = true
 If true, sections that contain both fields and subsections will render their subsections before their fields. More...
 
 $mTableId = ''
 
Title null $mTitle
 
string array $mTokenSalt = ''
 Salt for the edit token. More...
 
 $mUseMultipart = false
 
 $mValidationErrorMessage
 
 $mWasSubmitted = false
 
 $mWrapperAttributes = []
 
 $mWrapperLegend = false
 

Detailed Description

Object handling generic submission, CSRF protection, layout and other logic for UI forms in a reusable manner.

In order to generate the form, the HTMLForm object takes an array structure detailing the form fields available. Each element of the array is a basic property-list, including the type of field, the label it is to be given in the form, callbacks for validation and 'filtering', and other pertinent information.

Field types are implemented as subclasses of the generic HTMLFormField object, and typically implement at least getInputHTML, which generates the HTML for the input field to be placed in the table.

You can find extensive documentation on the www.mediawiki.org wiki:

The constructor input is an associative array of $fieldname => $info, where $info is an Associative Array with any of the following:

'class' – the subclass of HTMLFormField that will be used to create the object. NOT the CSS class! 'type' – roughly translates into the <select> type attribute. if 'class' is not specified, this is used as a map through HTMLForm::$typeMappings to get the class name. 'default' – default value when the form is displayed 'nodata' – if set (to any value, which casts to true), the data for this field will not be loaded from the actual request. Instead, always the default data is set as the value of this field. 'id' – HTML id attribute 'cssclass' – CSS class 'csshelpclass' – CSS class used to style help text 'dir' – Direction of the element. 'options' – associative array mapping raw text labels to values. Some field types support multi-level arrays. Overwrites 'options-message'. 'options-messages' – associative array mapping message keys to values. Some field types support multi-level arrays. Overwrites 'options' and 'options-message'. 'options-messages-parse' – Flag to parse the messages in 'options-messages'. 'options-message' – message key or object to be parsed to extract the list of options (like 'ipbreason-dropdown'). 'label-message' – message key or object for a message to use as the label. can be an array of msg key and then parameters to the message. 'label' – alternatively, a raw text message. Overridden by label-message 'help' – message text for a message to use as a help text. 'help-message' – message key or object for a message to use as a help text. can be an array of msg key and then parameters to the message. Overwrites 'help-messages' and 'help'. 'help-messages' – array of message keys/objects. As above, each item can be an array of msg key and then parameters. Overwrites 'help'. 'help-inline' – Whether help text (defined using options above) will be shown inline after the input field, rather than in a popup. Defaults to true. Only used by OOUI form fields. 'required' – passed through to the object, indicating that it is a required field. 'size' – the length of text fields 'filter-callback' – a function name to give you the chance to massage the inputted value before it's processed.

See also
HTMLFormField::filter() 'validation-callback' – a function name to give you the chance to impose extra validation on the field input.
HTMLFormField::validate() 'name' – By default, the 'name' attribute of the input field is "wp{$fieldname}". If you want a different name (eg one without the "wp" prefix), specify it here and it will be used without modification. 'hide-if' – expression given as an array stating when the field should be hidden. The first array value has to be the expression's logic operator. Supported expressions: 'NOT' [ 'NOT', array $expression ] To hide a field if a given expression is not true. '===' [ '===', string $fieldName, string $value ] To hide a field if another field identified by $field has the value $value. '!==' [ '!==', string $fieldName, string $value ] Same as [ 'NOT', [ '===', $fieldName, $value ] 'OR', 'AND', 'NOR', 'NAND' [ 'XXX', array $expression1, ..., array $expressionN ] To hide a field if one or more (OR), all (AND), neither (NOR) or not all (NAND) given expressions are evaluated as true. The expressions will be given to a JavaScript frontend module which will continually update the field's visibility. 'disable-if' – expression given as an array stating when the field should be disabled. See 'hide-if' for supported expressions. The 'hide-if' logic would also disable fields, you don't need to set this attribute with the same condition manually. You can pass both 'disabled' and this attribute to omit extra check, but this would function only for not 'disabled' fields. 'section' – A string name for the section of the form to which the field belongs. Subsections may be added using the separator '/', e.g.: 'section' => 'section1/subsection1' More levels may be added, e.g.: 'section' => 'section1/subsection2/subsubsection1' The message key for a section or subsection header is built from its name and the form's message prefix (if present).

Since 1.20, you can chain mutators to ease the form generation:

Example:
$form = new HTMLForm( $someFields, $this->getContext() );
$form->setMethod( 'get' )
->setWrapperLegendMsg( 'message-key' )
->prepareForm()
->displayForm( '' );
getContext()
Get the base IContextSource object.
Object handling generic submission, CSRF protection, layout and other logic for UI forms in a reusabl...
Definition: HTMLForm.php:150
Note that you will have prepareForm and displayForm at the end. Other method calls done after that would simply not be part of the form :(
Stability: stable
to extend

Definition at line 150 of file HTMLForm.php.

Constructor & Destructor Documentation

◆ __construct()

HTMLForm::__construct (   $descriptor,
IContextSource  $context,
  $messagePrefix = '' 
)

Build a new HTMLForm from an array of field attributes.

Stability: stable
to call
Parameters
array$descriptorArray of Field constructs, as described in the class documentation
IContextSource$contextContext used to fetch submitted form fields and generate localisation messages
string$messagePrefixA prefix to go in front of default messages

Definition at line 364 of file HTMLForm.php.

References addFields(), ContextSource\getConfig(), and ContextSource\setContext().

Member Function Documentation

◆ addButton()

HTMLForm::addButton (   $data)

Add a button to the form.

Since
1.27 takes an array as shown. Earlier versions accepted 'name', 'value', 'id', and 'attribs' as separate parameters in that order.
Parameters
array$dataData to define the button:
  • name: (string) Button name.
  • value: (string) Button value.
  • label-message: (string|string[]|MessageSpecifier, optional) Button label message key to use instead of 'value'. Overrides 'label' and 'label-raw'.
  • label: (string, optional) Button label text to use instead of 'value'. Overrides 'label-raw'.
  • label-raw: (string, optional) Button label HTML to use instead of 'value'.
  • id: (string, optional) DOM id for the button.
  • attribs: (array, optional) Additional HTML attributes.
  • flags: (string|string[], optional) OOUI flags.
  • framed: (boolean=true, optional) OOUI framed attribute. @phpcs:ignore Generic.Files.LineLength
Returns
HTMLForm $this for chaining calls (since 1.20)

Definition at line 1168 of file HTMLForm.php.

References $args.

Referenced by McrUndoAction\alterForm(), and SpecialBotPasswords\alterForm().

◆ addFields()

HTMLForm::addFields (   $descriptor)

Add fields to the form.

Since
1.34
Parameters
array$descriptorArray of Field constructs, as described in the class documentation
Returns
HTMLForm

Definition at line 390 of file HTMLForm.php.

Referenced by __construct(), and SpecialTags\processCreateTagForm().

◆ addFooterHtml()

HTMLForm::addFooterHtml (   $html,
  $section = null 
)

Add footer HTML, inside the form.

Parameters
string$htmlComplete text of message to display
string | null$sectionThe section to add the footer text to
Since
1.38
Returns
$this for chaining calls

Definition at line 963 of file HTMLForm.php.

Referenced by addFooterText().

◆ addFooterText()

HTMLForm::addFooterText (   $msg,
  $section = null 
)

Add footer text, inside the form.

Parameters
string$msgComplete text of message to display
string | null$sectionThe section to add the footer text to
Returns
HTMLForm $this for chaining calls (since 1.20)
Deprecated:
since 1.38, use addFooterHtml() instead

Definition at line 1019 of file HTMLForm.php.

References addFooterHtml().

Referenced by UploadForm\__construct().

◆ addHeaderHtml()

HTMLForm::addHeaderHtml (   $html,
  $section = null 
)

Add HTML to the header, inside the form.

Parameters
string$htmlAdditional HTML to display in header
string | null$sectionThe section to add the header to
Since
1.38
Returns
$this for chaining calls

Definition at line 866 of file HTMLForm.php.

Referenced by addHeaderText(), and SpecialUserLogout\alterForm().

◆ addHeaderText()

HTMLForm::addHeaderText (   $msg,
  $section = null 
)

Add HTML to the header, inside the form.

Parameters
string$msgAdditional HTML to display in header
string | null$sectionThe section to add the header to
Returns
HTMLForm $this for chaining calls (since 1.20)
Deprecated:
since 1.38, use addHeaderHtml() instead

Definition at line 923 of file HTMLForm.php.

References addHeaderHtml().

Referenced by SpecialBlock\alterForm(), SpecialChangeEmail\alterForm(), and UploadForm\getDescriptionSection().

◆ addHiddenField()

HTMLForm::addHiddenField (   $name,
  $value,
array  $attribs = [] 
)

Add a hidden field to the output.

Parameters
string$nameField name. This will be used exactly as entered
mixed$valueField value
array$attribs
Returns
HTMLForm $this for chaining calls (since 1.20)

Definition at line 1120 of file HTMLForm.php.

Referenced by McrRestoreAction\addStatePropagationFields(), McrUndoAction\addStatePropagationFields(), MarkpatrolledAction\alterForm(), RevertAction\alterForm(), and RollbackAction\alterForm().

◆ addHiddenFields()

HTMLForm::addHiddenFields ( array  $fields)

Add an array of hidden fields to the output.

Since
1.22
Parameters
array$fieldsAssociative array of fields to add; mapping names to their values
Returns
HTMLForm $this for chaining calls

Definition at line 1137 of file HTMLForm.php.

Referenced by SpecialChangeEmail\alterForm(), SpecialPasswordReset\alterForm(), and SpecialUserLogout\alterForm().

◆ addPostHtml()

HTMLForm::addPostHtml (   $html)

Add HTML to the end of the display.

Parameters
string$htmlComplete text of message to display
Since
1.38
Returns
$this for chaining calls

Definition at line 1057 of file HTMLForm.php.

Referenced by addPostText().

◆ addPostText()

HTMLForm::addPostText (   $msg)

Add text to the end of the display.

Parameters
string$msgComplete text of message to display
Returns
HTMLForm $this for chaining calls (since 1.20)
Deprecated:
since 1.38, use addPostHtml() instead

Definition at line 1095 of file HTMLForm.php.

References addPostHtml().

◆ addPreHtml()

HTMLForm::addPreHtml (   $html)

Add HTML to introductory message.

Parameters
string$htmlComplete HTML of message to display
Since
1.38
Returns
$this for chaining calls

Definition at line 806 of file HTMLForm.php.

Referenced by addPreText().

◆ addPreText()

HTMLForm::addPreText (   $msg)

Add HTML to introductory message.

Parameters
string$msgComplete HTML of message to display
Returns
HTMLForm $this for chaining calls (since 1.20)
Deprecated:
since 1.38, use addPreHtml() instead

Definition at line 842 of file HTMLForm.php.

References addPreHtml().

Referenced by SpecialBotPasswords\alterForm().

◆ displayForm()

HTMLForm::displayForm (   $submitResult)

Display the form (sending to the context's OutputPage object), with an appropriate error message or stack of messages, and any validation errors, etc.

Warning
You should call prepareForm() before calling this function. Moreover, when doing method chaining this should be the very last method call just after prepareForm().
Stability: stable
to override
Parameters
bool | string | array | Status$submitResultOutput from HTMLForm::trySubmit()
Returns
void Nothing, should be last call

Definition at line 1229 of file HTMLForm.php.

References getHTML(), and ContextSource\getOutput().

Referenced by show(), and showAlways().

◆ displaySection()

HTMLForm::displaySection (   $fields,
  $sectionName = '',
  $fieldsetIDPrefix = '',
$hasUserVisibleFields = false 
)
Todo:
Document
Stability: stable
to override
Parameters
array[] | HTMLFormField[]$fieldsArray of fields (either arrays or objects).
string$sectionNameID attribute of the "<table>" tag for this section, ignored if empty.
string$fieldsetIDPrefixID prefix for the "<fieldset>" tag of each subsection, ignored if empty.
bool&$hasUserVisibleFieldsWhether the section had user-visible fields.
Exceptions
LogicExceptionWhen called on uninitialized field data, e.g. When HTMLForm::displayForm was called without calling HTMLForm::prepareForm first.
Returns
string

Reimplemented in EditWatchlistNormalHTMLForm.

Definition at line 1879 of file HTMLForm.php.

References $displayFormat, Sanitizer\escapeIdForAttribute(), formatSection(), getDisplayFormat(), getFooterText(), getHeaderText(), getLegend(), and wrapFieldSetSection().

Referenced by getBody(), and PreferencesFormOOUI\getBody().

◆ factory()

static HTMLForm::factory (   $displayFormat,
  $descriptor,
IContextSource  $context,
  $messagePrefix = '' 
)
static

Construct a HTMLForm object for given display type.

May return a HTMLForm subclass.

Stability: stable
to call
Parameters
string$displayFormat
array$descriptorArray of Field constructs, as described in the class documentation
IContextSource$contextContext used to fetch submitted form fields and generate localisation messages
string$messagePrefixA prefix to go in front of default messages
Returns
HTMLForm

Definition at line 338 of file HTMLForm.php.

References ContextSource\$context, and $displayFormat.

Referenced by SpecialBookSources\buildForm(), ProtectionForm\buildForm(), SpecialActiveUsers\buildForm(), SpecialNewFiles\buildForm(), SpecialAllMessages\execute(), SpecialAutoblockList\execute(), SpecialBlockList\execute(), SpecialComparePages\execute(), SpecialExport\execute(), SpecialFileDuplicateSearch\execute(), SpecialLinkSearch\execute(), SpecialPagesWithProp\execute(), SpecialUnblock\execute(), SpecialNewpages\form(), AuthManagerSpecialPage\getAuthForm(), LoginSignupSpecialPage\getAuthForm(), FormAction\getForm(), FormSpecialPage\getForm(), ImageListPager\getForm(), SpecialContributions\getForm(), UsersPager\getPageHeader(), SpecialMIMESearch\getPageHeader(), SpecialWithoutInterwiki\getPageHeader(), CategoryPager\getStartForm(), SpecialExpandTemplates\makeForm(), SpecialPrefixindex\namespacePrefixForm(), HistoryAction\onView(), SpecialAllPages\outputHTMLForm(), SpecialEmailUser\sendEmailForm(), SpecialTags\showActivateDeactivateForm(), SpecialTags\showDeleteTagForm(), SpecialRedirectWithAction\showForm(), SpecialDiff\showForm(), SpecialImport\showForm(), SpecialNewSection\showForm(), SpecialPermanentLink\showForm(), SpecialProtectedtitles\showOptions(), SpecialProtectedpages\showOptions(), LogEventsList\showOptions(), SpecialConfirmEmail\showRequestForm(), SpecialPreferences\showResetForm(), SpecialTags\showTagList(), SpecialUploadStash\showUploads(), SpecialEmailUser\userForm(), and SpecialWhatLinksHere\whatlinkshereForm().

◆ filterDataForSubmit()

HTMLForm::filterDataForSubmit (   $data)

Overload this if you want to apply special filtration routines to the form as a whole, after it's submitted but before it's processed.

Stability: stable
to override
Parameters
array$data
Returns
array

Reimplemented in PreferencesFormOOUI.

Definition at line 2076 of file HTMLForm.php.

Referenced by trySubmit().

◆ formatErrors()

HTMLForm::formatErrors (   $errors)

Format a stack of error messages into a single HTML string.

Parameters
array$errorsArray of message keys/values
Returns
string HTML, a "<ul>" list of errors

Definition at line 1529 of file HTMLForm.php.

References getMessage(), and Html\rawElement().

Referenced by SpecialBlock\alterForm(), and getErrorsOrWarnings().

◆ formatSection()

HTMLForm::formatSection ( array  $fieldsHtml,
  $sectionName,
  $anyFieldHasLabel 
)
protected

Put a form section together from the individual fields' HTML, merging it and wrapping.

Stability: stable
to override
Parameters
array$fieldsHtml
string$sectionName
bool$anyFieldHasLabel
Returns
string HTML

Reimplemented in OOUIHTMLForm.

Definition at line 1973 of file HTMLForm.php.

References $displayFormat, Sanitizer\escapeIdForAttribute(), getDisplayFormat(), and Html\rawElement().

Referenced by displaySection().

◆ getAction()

HTMLForm::getAction ( )

Get the value for the action attribute of the form.

Since
1.22
Returns
string

Definition at line 2116 of file HTMLForm.php.

References $mAction, ContextSource\getConfig(), getMethod(), and getTitle().

Referenced by getFormAttributes(), and getHiddenFields().

◆ getBody()

HTMLForm::getBody ( )

Get the whole body of the form.

Stability: stable
to override
Returns
string

Reimplemented in PreferencesFormOOUI, and OOUIHTMLForm.

Definition at line 1475 of file HTMLForm.php.

References displaySection().

Referenced by getHTML().

◆ getButtons()

HTMLForm::getButtons ( )

Get the submit and (potentially) reset buttons.

Stability: stable
to override
Returns
string HTML.

Reimplemented in PreferencesFormOOUI, VFormHTMLForm, and OOUIHTMLForm.

Definition at line 1372 of file HTMLForm.php.

References $mSubmitID, $mSubmitName, Html\element(), getCancelTargetURL(), ContextSource\getConfig(), getMessage(), getSubmitText(), ContextSource\msg(), Html\rawElement(), Xml\submitButton(), and Linker\tooltipAndAccesskeyAttribs().

Referenced by getHTML().

◆ getCancelTargetURL()

HTMLForm::getCancelTargetURL ( )
protected
Since
1.37
Returns
string

Definition at line 1698 of file HTMLForm.php.

References $mCancelTarget, Title\castFromLinkTarget(), and Title\newMainPage().

Referenced by getButtons(), OOUIHTMLForm\getButtons(), and VFormHTMLForm\getButtons().

◆ getClassFromDescriptor()

static HTMLForm::getClassFromDescriptor (   $fieldname,
$descriptor 
)
static

Get the HTMLFormField subclass for this descriptor.

The descriptor can be passed either 'class' which is the name of a HTMLFormField subclass, or a shorter 'type' which is an alias. This makes sure the 'class' is always set, and also is returned by this function for ease.

Since
1.23
Parameters
string$fieldnameName of the field
array&$descriptorInput Descriptor, as described in the class documentation
Exceptions
MWException
Returns
string Name of a HTMLFormField subclass

Definition at line 510 of file HTMLForm.php.

◆ getDisplayFormat()

HTMLForm::getDisplayFormat ( )

Getter for displayFormat.

Since
1.20
Returns
string

Definition at line 489 of file HTMLForm.php.

References $displayFormat.

Referenced by displaySection(), formatSection(), and HTMLCheckField\getLabel().

◆ getErrorsOrWarnings()

HTMLForm::getErrorsOrWarnings (   $elements,
  $elementsType 
)

Returns a formatted list of errors or warnings from the given elements.

Stability: stable
to override
Parameters
string | array | Status$elementsThe set of errors/warnings to process.
string$elementsTypeShould warnings or errors be returned. This is meant for Status objects, all other valid types are always considered as errors.
Returns
string

Reimplemented in OOUIHTMLForm.

Definition at line 1488 of file HTMLForm.php.

References Html\errorBox(), formatErrors(), and Html\warningBox().

Referenced by getHTML().

◆ getField()

HTMLForm::getField (   $fieldname)
Parameters
string$fieldname
Returns
HTMLFormField
Exceptions
DomainExceptionon invalid field name

Definition at line 436 of file HTMLForm.php.

References hasField().

◆ getFooterHtml()

HTMLForm::getFooterHtml (   $section = null)

Get footer HTML.

Parameters
string | null$sectionThe section to get the footer text for
Since
1.38
Returns
string

Definition at line 1002 of file HTMLForm.php.

References $mFooter.

Referenced by getFooterText().

◆ getFooterText()

HTMLForm::getFooterText (   $section = null)

Get footer text.

Parameters
string | null$sectionThe section to get the footer text for
Since
1.26
Returns
string
Deprecated:
since 1.38, use getFooterHtml() instead

Definition at line 1045 of file HTMLForm.php.

References getFooterHtml().

Referenced by displaySection(), PreferencesFormOOUI\getBody(), and getHTML().

◆ getFormAttributes()

HTMLForm::getFormAttributes ( )
protected

Get HTML attributes for the <form> tag.

Stability: stable
to override
Returns
array

Reimplemented in VFormHTMLForm.

Definition at line 1286 of file HTMLForm.php.

References $mAutocomplete, $mId, $mName, getAction(), getMethod(), and needsJSForHtml5FormValidation().

Referenced by wrapForm(), and OOUIHTMLForm\wrapForm().

◆ getHeaderHtml()

HTMLForm::getHeaderHtml (   $section = null)

Get header HTML.

Stability: stable
to override
Parameters
string | null$sectionThe section to get the header text for
Since
1.38
Returns
string HTML

Reimplemented in OOUIHTMLForm.

Definition at line 906 of file HTMLForm.php.

References $mHeader.

Referenced by getHeaderText().

◆ getHeaderText()

HTMLForm::getHeaderText (   $section = null)

Get header text.

Stability: stable
to override
Parameters
string | null$sectionThe section to get the header text for
Since
1.26
Returns
string HTML
Deprecated:
since 1.38, use getHeaderHtml() instead

Definition at line 950 of file HTMLForm.php.

References getHeaderHtml().

Referenced by displaySection(), PreferencesFormOOUI\getBody(), and getHTML().

◆ getHiddenFields()

HTMLForm::getHiddenFields ( )

Get the hidden fields that should go inside the form.

Returns
string HTML.

Definition at line 1339 of file HTMLForm.php.

References getAction(), ContextSource\getConfig(), getMethod(), getTitle(), ContextSource\getUser(), and Html\hidden().

Referenced by getHTML().

◆ getHTML()

HTMLForm::getHTML (   $submitResult)

Returns the raw HTML generated by the form.

Stability: stable
to override
Parameters
bool | string | array | Status$submitResultOutput from HTMLForm::trySubmit()
Returns
string HTML
-taint escaped

Reimplemented in VFormHTMLForm.

Definition at line 1243 of file HTMLForm.php.

References $mPost, getBody(), getButtons(), getErrorsOrWarnings(), getFooterText(), getHeaderText(), getHiddenFields(), ContextSource\getOutput(), and wrapForm().

Referenced by displayForm().

◆ getLegend()

HTMLForm::getLegend (   $key)

Get a string to go in the "<legend>" of a section fieldset.

Override this if you want something more complicated.

Stability: stable
to override
Parameters
string$key
Returns
string Plain text (not HTML-escaped)

Reimplemented in EditWatchlistNormalHTMLForm, and PreferencesFormOOUI.

Definition at line 2089 of file HTMLForm.php.

References ContextSource\msg().

Referenced by displaySection().

◆ getMessage()

HTMLForm::getMessage (   $value)
protected

Turns a *-message parameter (which could be a MessageSpecifier, or a message name, or a name + parameters array) into a Message.

Parameters
mixed$value
Returns
Message

Definition at line 2157 of file HTMLForm.php.

References Message\newFromSpecifier().

Referenced by formatErrors(), getButtons(), OOUIHTMLForm\getButtons(), and OOUIHTMLForm\getErrorsOrWarnings().

◆ getMethod()

HTMLForm::getMethod ( )
Returns
string Always lowercase

Definition at line 1844 of file HTMLForm.php.

References $mMethod.

Referenced by getAction(), getFormAttributes(), getHiddenFields(), and tryAuthorizedSubmit().

◆ getPostHtml()

HTMLForm::getPostHtml ( )

Get HTML at the end of the display.

Since
1.38
Returns
string HTML

Definition at line 1083 of file HTMLForm.php.

References $mPost.

◆ getPreHtml()

HTMLForm::getPreHtml ( )

Get the introductory message HTML.

Since
1.38
Returns
string

Definition at line 818 of file HTMLForm.php.

References $mPre.

Referenced by getPreText().

◆ getPreText()

HTMLForm::getPreText ( )

Get the introductory message HTML.

Since
1.32
Returns
string
Deprecated:
since 1.38, use getPreHtml() instead

Definition at line 853 of file HTMLForm.php.

References getPreHtml().

◆ getSubmitText()

HTMLForm::getSubmitText ( )

Get the text for the submit button, either customised or a default.

Returns
string

Definition at line 1591 of file HTMLForm.php.

References ContextSource\msg().

Referenced by getButtons(), OOUIHTMLForm\getButtons(), and VFormHTMLForm\getButtons().

◆ getTitle()

HTMLForm::getTitle ( )

◆ hasField()

HTMLForm::hasField (   $fieldname)
Parameters
string$fieldname
Returns
bool

Definition at line 427 of file HTMLForm.php.

Referenced by getField().

◆ loadData()

HTMLForm::loadData ( )
Deprecated:
since 1.39, Use prepareForm() instead.

Definition at line 2013 of file HTMLForm.php.

References prepareForm().

◆ loadFieldData()

HTMLForm::loadFieldData ( )
protected

Load data of form fields from the request.

Definition at line 2020 of file HTMLForm.php.

References ContextSource\getRequest().

Referenced by prepareForm().

◆ loadInputFromParameters()

static HTMLForm::loadInputFromParameters (   $fieldname,
  $descriptor,
HTMLForm  $parent = null 
)
static

Initialise a new Object for the field.

Stability: stable
to override
Parameters
string$fieldnameName of the field
array$descriptorInput Descriptor, as described in the class documentation
HTMLForm | null$parentParent instance of HTMLForm
Exceptions
MWException
Returns
HTMLFormField Instance of a subclass of HTMLFormField

Reimplemented in VFormHTMLForm, and OOUIHTMLForm.

Definition at line 540 of file HTMLForm.php.

Referenced by HTMLFormFieldCloner\createFieldsForKey().

◆ needsJSForHtml5FormValidation()

HTMLForm::needsJSForHtml5FormValidation ( )

Whether this form, with its current fields, requires the user agent to have JavaScript enabled for the client-side HTML5 form validation to work correctly.

If this function returns true, a 'novalidate' attribute will be added on the <form> element. It will be removed if the user agent has JavaScript support, in htmlform.js.

Returns
bool
Since
1.29

Definition at line 2170 of file HTMLForm.php.

Referenced by getFormAttributes().

◆ prepareForm()

HTMLForm::prepareForm ( )

Prepare form for submission.

Warning
When doing method chaining, that should be the very last method call before displayForm().
Exceptions
MWException
Returns
HTMLForm $this for chaining calls (since 1.20)

Definition at line 565 of file HTMLForm.php.

References ContextSource\getRequest(), and loadFieldData().

Referenced by loadData(), show(), and showAlways().

◆ setAction()

HTMLForm::setAction (   $action)

Set the value for the action attribute of the form.

When set to false (which is the default state), the set title is used.

Since
1.19
Parameters
string | bool$action
Returns
HTMLForm $this for chaining calls (since 1.20)

Definition at line 2103 of file HTMLForm.php.

◆ setAutocomplete()

HTMLForm::setAutocomplete (   $autocomplete)

Set the value for the autocomplete attribute of the form.

A typical value is "off". When set to null (which is the default state), the attribute get not set.

Since
1.27
Parameters
string | null$autocomplete
Returns
HTMLForm $this for chaining calls

Definition at line 2145 of file HTMLForm.php.

◆ setCancelTarget()

HTMLForm::setCancelTarget (   $target)

Sets the target where the user is redirected to after clicking cancel.

Parameters
LinkTarget | PageReference | string$targetTarget as an object or an URL
Returns
HTMLForm $this for chaining calls
Since
1.27

Definition at line 1685 of file HTMLForm.php.

References TitleValue\castPageToLinkTarget().

Referenced by McrUndoAction\alterForm().

◆ setCollapsibleOptions()

HTMLForm::setCollapsibleOptions (   $collapsedByDefault = false)

Enable collapsible mode, and set whether the form is collapsed by default.

Since
1.34
Parameters
bool$collapsedByDefaultWhether the form is collapsed by default (optional).
Returns
HTMLForm $this for chaining calls

Definition at line 1275 of file HTMLForm.php.

◆ setDisplayFormat()

HTMLForm::setDisplayFormat (   $format)

Set format in which to display the form.

Parameters
string$formatThe name of the format to use, must be one of $this->availableDisplayFormats
Exceptions
MWException
Since
1.20
Returns
HTMLForm $this for chaining calls (since 1.20)

Definition at line 453 of file HTMLForm.php.

References ContextSource\getConfig().

◆ setFooterHtml()

HTMLForm::setFooterHtml (   $html,
  $section = null 
)

Set footer HTML, inside the form.

Parameters
string$htmlComplete text of message to display
string | null$sectionThe section to add the footer text to
Since
1.38
Returns
$this for chaining calls

Definition at line 985 of file HTMLForm.php.

Referenced by setFooterText().

◆ setFooterText()

HTMLForm::setFooterText (   $msg,
  $section = null 
)

Set footer text, inside the form.

Since
1.19
Parameters
string$msgComplete text of message to display
string | null$sectionThe section to add the footer text to
Returns
HTMLForm $this for chaining calls (since 1.20)
Deprecated:
since 1.38, use setFooterHtml() instead

Definition at line 1033 of file HTMLForm.php.

References setFooterHtml().

◆ setFormIdentifier()

HTMLForm::setFormIdentifier (   $ident)

Set an internal identifier for this form.

It will be submitted as a hidden form field, allowing HTMLForm to determine whether the form was submitted (or merely viewed). Setting this serves two purposes:

  • If you use two or more forms on one page, it allows HTMLForm to identify which of the forms was submitted, and not attempt to validate the other ones.
  • If you use checkbox or multiselect fields inside a form using the GET method, it allows HTMLForm to distinguish between the initial page view and a form submission with all checkboxes or select options unchecked.
Since
1.28
Parameters
string$ident
Returns
$this

Definition at line 1646 of file HTMLForm.php.

Referenced by SpecialChangeContentModel\alterForm().

◆ setHeaderHtml()

HTMLForm::setHeaderHtml (   $html,
  $section = null 
)

Set header HTML, inside the form.

Parameters
string$htmlComplete HTML of header to display
string | null$sectionThe section to add the header to
Since
1.38
Returns
$this for chaining calls

Definition at line 888 of file HTMLForm.php.

Referenced by setHeaderText().

◆ setHeaderText()

HTMLForm::setHeaderText (   $msg,
  $section = null 
)

Set header text, inside the form.

Parameters
string$msgComplete HTML of header to display
string | null$sectionThe section to add the header to
Since
1.19
Returns
HTMLForm $this for chaining calls (since 1.20)
Deprecated:
since 1.38, use setHeaderHtml() instead

Definition at line 937 of file HTMLForm.php.

References setHeaderHtml().

Referenced by SpecialBlock\alterForm(), SpecialPasswordReset\alterForm(), and SpecialTags\processCreateTagForm().

◆ setId()

HTMLForm::setId (   $id)
Parameters
string$idDOM id for the form
Returns
HTMLForm $this for chaining calls (since 1.20)

Definition at line 1728 of file HTMLForm.php.

Referenced by UploadForm\__construct(), McrUndoAction\alterForm(), SpecialBotPasswords\alterForm(), and SpecialChangeEmail\alterForm().

◆ setIntro()

HTMLForm::setIntro (   $msg)

Set the introductory message, overwriting any existing message.

Parameters
string$msgComplete text of message to display
Returns
HTMLForm $this for chaining calls (since 1.20)
Deprecated:
since 1.38, use setPreHtml() instead

Definition at line 780 of file HTMLForm.php.

References setPreHtml().

◆ setMessagePrefix()

HTMLForm::setMessagePrefix (   $p)

Set the prefix for various default messages.

Todo:
Currently only used for the "<fieldset>" legend on forms with multiple sections; should be used elsewhere?
Parameters
string$p
Returns
HTMLForm $this for chaining calls (since 1.20)

Definition at line 1801 of file HTMLForm.php.

◆ setMethod()

HTMLForm::setMethod (   $method = 'post')

Set the method used to submit the form.

Parameters
string$method
Returns
HTMLForm $this for chaining calls (since 1.20)

Definition at line 1835 of file HTMLForm.php.

Referenced by SpecialRedirect\alterForm().

◆ setName()

HTMLForm::setName (   $name)
Parameters
string$name'name' attribute for the form
Returns
HTMLForm $this for chaining calls

Definition at line 1738 of file HTMLForm.php.

◆ setPostHtml()

HTMLForm::setPostHtml (   $html)

Set HTML at the end of the display.

Parameters
string$htmlComplete text of message to display
Since
1.38
Returns
$this for chaining calls

Definition at line 1071 of file HTMLForm.php.

Referenced by setPostText().

◆ setPostText()

HTMLForm::setPostText (   $msg)

Set text at the end of the display.

Parameters
string$msgComplete text of message to display
Returns
HTMLForm $this for chaining calls (since 1.20)
Deprecated:
since 1.38, use setPostHtml() instead

Definition at line 1107 of file HTMLForm.php.

References setPostHtml().

◆ setPreHtml()

HTMLForm::setPreHtml (   $html)

Set the introductory message HTML, overwriting any existing message.

Parameters
string$htmlComplete HTML of message to display
Since
1.38
Returns
$this for chaining calls

Definition at line 792 of file HTMLForm.php.

Referenced by setIntro(), and setPreText().

◆ setPreText()

HTMLForm::setPreText (   $msg)

Set the introductory message HTML, overwriting any existing message.

Parameters
string$msgComplete HTML of message to display
Returns
HTMLForm $this for chaining calls (since 1.20)
Deprecated:
since 1.38, use setPreHtml() instead

Definition at line 830 of file HTMLForm.php.

References setPreHtml().

◆ setSubmitCallback()

HTMLForm::setSubmitCallback (   $cb)

Set a callback to a function to do something with the form once it's been successfully validated.

Parameters
callable$cbThe function will be passed the output from HTMLForm::filterDataForSubmit and this HTMLForm object, and must return as documented for HTMLForm::trySubmit
Returns
HTMLForm $this for chaining calls (since 1.20)

Definition at line 752 of file HTMLForm.php.

◆ setSubmitDestructive()

HTMLForm::setSubmitDestructive ( )

Identify that the submit button in the form has a destructive action.

Since
1.24
Returns
HTMLForm $this for chaining calls (since 1.28)

Definition at line 1564 of file HTMLForm.php.

Referenced by SpecialBlock\alterForm(), SpecialPasswordReset\alterForm(), and SpecialResetTokens\alterForm().

◆ setSubmitID()

HTMLForm::setSubmitID (   $t)

Set the id for the submit button.

Parameters
string$t
Todo:
FIXME: Integrity of $t is not validated
Returns
HTMLForm $this for chaining calls (since 1.20)

Definition at line 1625 of file HTMLForm.php.

References $t.

◆ setSubmitName()

HTMLForm::setSubmitName (   $name)
Parameters
string$nameSubmit button name
Returns
HTMLForm $this for chaining calls (since 1.20)

Definition at line 1600 of file HTMLForm.php.

Referenced by UploadForm\__construct(), and McrUndoAction\alterForm().

◆ setSubmitText()

HTMLForm::setSubmitText (   $t)

Set the text for the submit button.

Parameters
string$tPlaintext
Returns
HTMLForm $this for chaining calls (since 1.20)

Definition at line 1552 of file HTMLForm.php.

References $t.

Referenced by setSubmitTextMsg().

◆ setSubmitTextMsg()

◆ setSubmitTooltip()

HTMLForm::setSubmitTooltip (   $name)
Parameters
string$nameTooltip for the submit button
Returns
HTMLForm $this for chaining calls (since 1.20)

Definition at line 1611 of file HTMLForm.php.

Referenced by UploadForm\__construct(), and McrUndoAction\alterForm().

◆ setTableId()

HTMLForm::setTableId (   $id)

Set the id of the \<table\> or outermost \<div\> element.

Since
1.22
Parameters
string$idNew value of the id attribute, or "" to remove
Returns
HTMLForm $this for chaining calls

Definition at line 1717 of file HTMLForm.php.

Referenced by SpecialBotPasswords\alterForm(), and SpecialChangeEmail\alterForm().

◆ setTitle()

HTMLForm::setTitle (   $t)

Set the title for form submission.

Parameters
PageReference$tThe page the form is on/should be posted to
Returns
HTMLForm $this for chaining calls (since 1.20)

Definition at line 1814 of file HTMLForm.php.

References $t, and Title\castFromPageReference().

◆ setTokenSalt()

HTMLForm::setTokenSalt (   $salt)

Set the salt for the edit token.

Only useful when the method is "post".

Since
1.24
Parameters
string | array$saltSalt to use
Returns
HTMLForm $this For chaining calls

Definition at line 1209 of file HTMLForm.php.

Referenced by MarkpatrolledAction\alterForm(), RevertAction\alterForm(), RollbackAction\alterForm(), WatchAction\alterForm(), and SpecialUserLogout\alterForm().

◆ setValidationErrorMessage()

HTMLForm::setValidationErrorMessage (   $msg)

Set a message to display on a validation error.

Parameters
array$msgArray of valid inputs to wfMessage() (so each entry must itself be an array of arguments)
Returns
HTMLForm $this for chaining calls (since 1.20)

Definition at line 766 of file HTMLForm.php.

◆ setWrapperAttributes()

HTMLForm::setWrapperAttributes (   $attributes)

For internal use only.

Use is discouraged, and should only be used where support for gadgets/user scripts is warranted.

Parameters
array$attributes
Access: internal
Returns
HTMLForm $this for chaining calls

Definition at line 1768 of file HTMLForm.php.

◆ setWrapperLegend()

HTMLForm::setWrapperLegend (   $legend)

Prompt the whole form to be wrapped in a "<fieldset>", with this text as its "<legend>" element.

Parameters
string | bool$legendIf false, no wrapper or legend will be displayed. If true, a wrapper will be displayed, but no legend. If a string, a wrapper will be displayed with that string as a legend. The string will be escaped before being output (this doesn't support HTML).
Returns
HTMLForm $this for chaining calls (since 1.20)

Definition at line 1755 of file HTMLForm.php.

Referenced by SpecialLockdb\alterForm(), SpecialUnlockdb\alterForm(), and setWrapperLegendMsg().

◆ setWrapperLegendMsg()

HTMLForm::setWrapperLegendMsg (   $msg)

Prompt the whole form to be wrapped in a "<fieldset>", with this message as its "<legend>" element.

Since
1.19
Parameters
string | Message$msgMessage key or Message object
Returns
HTMLForm $this for chaining calls (since 1.20)

Definition at line 1783 of file HTMLForm.php.

References ContextSource\msg(), and setWrapperLegend().

Referenced by McrRestoreAction\alterForm(), McrUndoAction\alterForm(), PurgeAction\alterForm(), RevertAction\alterForm(), RollbackAction\alterForm(), UnwatchAction\alterForm(), WatchAction\alterForm(), and SpecialBotPasswords\alterForm().

◆ show()

HTMLForm::show ( )

The here's-one-I-made-earlier option: do the submission if posted, or display the form with or without funky validation errors.

Stability: stable
to override
Returns
bool|Status Whether submission was successful.

Reimplemented in UploadForm.

Definition at line 622 of file HTMLForm.php.

References displayForm(), StatusValue\isGood(), prepareForm(), and tryAuthorizedSubmit().

Referenced by SpecialUnblock\execute().

◆ showAlways()

HTMLForm::showAlways ( )

Same as self::show with the difference, that the form will be added to the output, no matter, if the validation was good or not.

Returns
bool|Status Whether submission was successful.

Definition at line 640 of file HTMLForm.php.

References displayForm(), prepareForm(), and tryAuthorizedSubmit().

◆ showCancel()

HTMLForm::showCancel (   $show = true)

Show a cancel button (or prevent it).

The button is not shown by default.

Parameters
bool$show
Returns
HTMLForm $this for chaining calls
Since
1.27

Definition at line 1674 of file HTMLForm.php.

Referenced by McrUndoAction\alterForm().

◆ suppressDefaultSubmit()

HTMLForm::suppressDefaultSubmit (   $suppressSubmit = true)

Stop a default submit button being shown for this form.

This implies that an alternate submit method must be provided manually.

Since
1.22
Parameters
bool$suppressSubmitSet to false to re-enable the button again
Returns
HTMLForm $this for chaining calls

Definition at line 1662 of file HTMLForm.php.

Referenced by SpecialBotPasswords\alterForm(), and SpecialResetTokens\alterForm().

◆ suppressReset()

HTMLForm::suppressReset (   $suppressReset = true)

Stop a reset button being shown for this form.

Parameters
bool$suppressResetSet to false to re-enable the button again
Returns
HTMLForm $this for chaining calls (since 1.20)

Definition at line 2060 of file HTMLForm.php.

◆ tryAuthorizedSubmit()

HTMLForm::tryAuthorizedSubmit ( )

Try submitting, with edit token check first.

Returns
bool|string|array|Status As documented for HTMLForm::trySubmit

Definition at line 583 of file HTMLForm.php.

References $mFormIdentifier, getMethod(), ContextSource\getRequest(), ContextSource\getUser(), and trySubmit().

Referenced by show(), and showAlways().

◆ trySubmit()

HTMLForm::trySubmit ( )

Validate all the fields, and call the submission callback function if everything is kosher.

Stability: stable
to override
Exceptions
MWException
Returns
bool|string|array|Status
  • Bool true or a good Status object indicates success,
  • Bool false indicates no submission was attempted,
  • Anything else indicates failure. The value may be a fatal Status object, an HTML string, or an array of arrays (message keys and params) or strings (message keys)

Reimplemented in UploadForm.

Definition at line 662 of file HTMLForm.php.

References $mSubmitCallback, $res, filterDataForSubmit(), and StatusValue\newGood().

Referenced by tryAuthorizedSubmit().

◆ wasSubmitted()

HTMLForm::wasSubmitted ( )

Test whether the form was considered to have been submitted or not, i.e.

whether the last call to tryAuthorizedSubmit or trySubmit returned non-false.

This will return false until HTMLForm::tryAuthorizedSubmit or HTMLForm::trySubmit is called.

Since
1.23
Returns
bool

Definition at line 738 of file HTMLForm.php.

References $mWasSubmitted.

◆ wrapFieldSetSection()

HTMLForm::wrapFieldSetSection (   $legend,
  $section,
  $attributes,
  $isRoot 
)
protected

Wraps the given $section into an user-visible fieldset.

Stability: stable
to override
Parameters
string$legendLegend text for the fieldset
string$sectionThe section content in plain Html
array$attributesAdditional attributes for the fieldset
bool$isRootSection is at the root of the tree
Returns
string The fieldset's Html

Reimplemented in PreferencesFormOOUI, and OOUIHTMLForm.

Definition at line 1858 of file HTMLForm.php.

References Xml\fieldset().

Referenced by displaySection().

◆ wrapForm()

HTMLForm::wrapForm (   $html)

Wrap the form innards in an actual "<form>" element.

Stability: stable
to override
Parameters
string$htmlHTML contents to wrap.
Returns
string Wrapped HTML.

Reimplemented in PreferencesFormOOUI, VFormHTMLForm, and OOUIHTMLForm.

Definition at line 1321 of file HTMLForm.php.

References Xml\fieldset(), getFormAttributes(), and Html\rawElement().

Referenced by getHTML().

Member Data Documentation

◆ $availableDisplayFormats

array HTMLForm::$availableDisplayFormats
protected
Initial value:
= [
'table',
'div',
'raw',
'inline',
]

Available formats in which to display the form.

Definition at line 309 of file HTMLForm.php.

◆ $availableSubclassDisplayFormats

array HTMLForm::$availableSubclassDisplayFormats
protected
Initial value:
= [
'vform',
'ooui',
]

Available formats in which to display the form.

Definition at line 320 of file HTMLForm.php.

◆ $displayFormat

string HTMLForm::$displayFormat = 'table'
protected

Format in which to display form.

For viable options,

See also
$availableDisplayFormats

Definition at line 303 of file HTMLForm.php.

Referenced by displaySection(), factory(), formatSection(), and getDisplayFormat().

◆ $mAction

bool string HTMLForm::$mAction = false
protected

Form action URL.

false means we will use the URL to set Title

Since
1.19

Definition at line 244 of file HTMLForm.php.

Referenced by getAction().

◆ $mAutocomplete

string null HTMLForm::$mAutocomplete = null
protected

Form attribute autocomplete.

A typical value is "off". null does not set the attribute

Since
1.27

Definition at line 265 of file HTMLForm.php.

Referenced by getFormAttributes().

◆ $mButtons

array [] HTMLForm::$mButtons = []
protected

Definition at line 277 of file HTMLForm.php.

◆ $mCancelTarget

HTMLForm::$mCancelTarget
protected

Definition at line 213 of file HTMLForm.php.

Referenced by getCancelTargetURL().

◆ $mCollapsed

bool HTMLForm::$mCollapsed = false
protected

Whether the form is collapsed by default.

Since
1.34

Definition at line 258 of file HTMLForm.php.

◆ $mCollapsible

bool HTMLForm::$mCollapsible = false
protected

Whether the form can be collapsed.

Since
1.34

Definition at line 251 of file HTMLForm.php.

◆ $mFieldData

HTMLForm::$mFieldData

Definition at line 201 of file HTMLForm.php.

◆ $mFieldTree

HTMLForm::$mFieldTree = []
protected

Definition at line 207 of file HTMLForm.php.

◆ $mFlatFields

HTMLFormField [] HTMLForm::$mFlatFields = []
protected

Definition at line 206 of file HTMLForm.php.

◆ $mFooter

HTMLForm::$mFooter = ''
protected

Definition at line 220 of file HTMLForm.php.

Referenced by getFooterHtml().

◆ $mFormIdentifier

HTMLForm::$mFormIdentifier
protected

Definition at line 233 of file HTMLForm.php.

Referenced by tryAuthorizedSubmit().

◆ $mHeader

HTMLForm::$mHeader = ''
protected

Definition at line 219 of file HTMLForm.php.

Referenced by getHeaderHtml().

◆ $mHiddenFields

array [] HTMLForm::$mHiddenFields = []
protected

Definition at line 272 of file HTMLForm.php.

◆ $mId

HTMLForm::$mId
protected

Definition at line 224 of file HTMLForm.php.

Referenced by getFormAttributes().

◆ $mMessagePrefix

HTMLForm::$mMessagePrefix
protected

Definition at line 203 of file HTMLForm.php.

◆ $mMethod

HTMLForm::$mMethod = 'post'
protected

Definition at line 236 of file HTMLForm.php.

Referenced by getMethod().

◆ $mName

HTMLForm::$mName
protected

Definition at line 225 of file HTMLForm.php.

Referenced by getFormAttributes().

◆ $mPost

HTMLForm::$mPost = ''
protected

Definition at line 223 of file HTMLForm.php.

Referenced by getHTML(), and getPostHtml().

◆ $mPre

HTMLForm::$mPre = ''
protected

Definition at line 218 of file HTMLForm.php.

Referenced by getPreHtml().

◆ $mSectionFooters

HTMLForm::$mSectionFooters = []
protected

Definition at line 222 of file HTMLForm.php.

◆ $mSectionHeaders

HTMLForm::$mSectionHeaders = []
protected

Definition at line 221 of file HTMLForm.php.

◆ $mShowCancel

HTMLForm::$mShowCancel = false
protected

Definition at line 212 of file HTMLForm.php.

◆ $mShowReset

HTMLForm::$mShowReset = false
protected

Definition at line 208 of file HTMLForm.php.

◆ $mShowSubmit

HTMLForm::$mShowSubmit = true
protected

Definition at line 209 of file HTMLForm.php.

◆ $mSubmitCallback

HTMLForm::$mSubmitCallback
protected

Definition at line 215 of file HTMLForm.php.

Referenced by trySubmit().

◆ $mSubmitFlags

string [] HTMLForm::$mSubmitFlags = [ 'primary', 'progressive' ]
protected

Definition at line 211 of file HTMLForm.php.

Referenced by OOUIHTMLForm\getButtons().

◆ $mSubmitID

HTMLForm::$mSubmitID
protected

Definition at line 228 of file HTMLForm.php.

Referenced by getButtons(), OOUIHTMLForm\getButtons(), and VFormHTMLForm\getButtons().

◆ $mSubmitName

HTMLForm::$mSubmitName
protected

Definition at line 229 of file HTMLForm.php.

Referenced by getButtons(), OOUIHTMLForm\getButtons(), and VFormHTMLForm\getButtons().

◆ $mSubmitText

HTMLForm::$mSubmitText
protected

Definition at line 230 of file HTMLForm.php.

◆ $mSubmitTooltip

HTMLForm::$mSubmitTooltip
protected

Definition at line 231 of file HTMLForm.php.

◆ $mSubSectionBeforeFields

bool HTMLForm::$mSubSectionBeforeFields = true
protected

If true, sections that contain both fields and subsections will render their subsections before their fields.

Subclasses may set this to false to render subsections after fields instead.

Definition at line 296 of file HTMLForm.php.

◆ $mTableId

HTMLForm::$mTableId = ''
protected

Definition at line 226 of file HTMLForm.php.

◆ $mTitle

Title null HTMLForm::$mTitle
protected

Definition at line 235 of file HTMLForm.php.

◆ $mTokenSalt

string array HTMLForm::$mTokenSalt = ''
protected

Salt for the edit token.

Definition at line 286 of file HTMLForm.php.

◆ $mUseMultipart

HTMLForm::$mUseMultipart = false
protected

Definition at line 267 of file HTMLForm.php.

◆ $mValidationErrorMessage

HTMLForm::$mValidationErrorMessage
protected

Definition at line 216 of file HTMLForm.php.

◆ $mWasSubmitted

HTMLForm::$mWasSubmitted = false
protected

Definition at line 237 of file HTMLForm.php.

Referenced by wasSubmitted().

◆ $mWrapperAttributes

HTMLForm::$mWrapperAttributes = []
protected

Definition at line 280 of file HTMLForm.php.

◆ $mWrapperLegend

HTMLForm::$mWrapperLegend = false
protected

Definition at line 279 of file HTMLForm.php.

◆ $typeMappings

string [] HTMLForm::$typeMappings
static

A mapping of 'type' inputs onto standard HTMLFormField subclasses.

Definition at line 154 of file HTMLForm.php.

Referenced by AuthManagerSpecialPage\addTabIndex(), and HTMLExpiryField\getFieldByType().


The documentation for this class was generated from the following file: