MediaWiki  1.23.13
HTMLForm Class Reference

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

Inheritance diagram for HTMLForm:
Collaboration diagram for HTMLForm:

Public Member Functions

 __construct ( $descriptor, $context=null, $messagePrefix='')
 Build a new HTMLForm from an array of field attributes. More...
 
 addButton ( $name, $value, $id=null, $attribs=null)
 Add a button to the form. More...
 
 addFooterText ( $msg, $section=null)
 Add footer text, inside the form. More...
 
 addHeaderText ( $msg, $section=null)
 Add header text, inside the form. More...
 
 addHiddenField ( $name, $value, $attribs=array())
 Add a hidden field to the output. More...
 
 addHiddenFields (array $fields)
 Add an array of hidden fields to the output. More...
 
 addPostText ( $msg)
 Add text to the end of the display. More...
 
 addPreText ( $msg)
 Add introductory text. 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...
 
 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...
 
 getErrors ( $errors)
 Format and display an error message stack. 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 ()
 
 getSubmitText ()
 Get the text for the submit button, either customised or a default. More...
 
 getTitle ()
 Get the title. More...
 
 isVForm ()
 Test if displayFormat is 'vform'. More...
 
 loadData ()
 Construct the form fields from the Descriptor array. More...
 
 prepareForm ()
 Prepare form for submission. More...
 
 setAction ( $action)
 Set the value for the action attribute of the form. More...
 
 setDisplayFormat ( $format)
 Set format in which to display the form. More...
 
 setFooterText ( $msg, $section=null)
 Set footer text, 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...
 
 setPostText ( $msg)
 Set text at the end of the display. More...
 
 setPreText ( $msg)
 Set the introductory message, 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...
 
 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...
 
 setValidationErrorMessage ( $msg)
 Set a message to display on a validation error. 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...
 
 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...
 
 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...
 
 getConfig ()
 Get the Config object. More...
 
 getContext ()
 Get the RequestContext object. More...
 
 getLang ()
 Get the Language object. More...
 
 getLanguage ()
 Get the Language object. More...
 
 getOutput ()
 Get the OutputPage object. More...
 
 getRequest ()
 Get the WebRequest object. More...
 
 getSkin ()
 Get the Skin object. More...
 
 getUser ()
 Get the User object. More...
 
 getWikiPage ()
 Get the WikiPage object. More...
 
 msg ()
 Get a Message object with context set Parameters are the same as wfMessage() More...
 
 setContext (IContextSource $context)
 Set the IContextSource object. More...
 

Static Public Member Functions

static addJS ()
 Add the HTMLForm-specific JavaScript, if it hasn't been done already. More...
 
static formatErrors ( $errors)
 Format a stack of error messages into a single HTML string. More...
 
static getClassFromDescriptor ( $fieldname, &$descriptor)
 Get the HTMLFormField subclass for this descriptor. More...
 
static loadInputFromParameters ( $fieldname, $descriptor)
 Initialise a new Object for the field. More...
 

Public Attributes

 $mFieldData
 

Static Public Attributes

static $typeMappings
 

Protected Attributes

Array $availableDisplayFormats
 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...
 
 $mButtons = array()
 
 $mFieldTree
 
HTMLFormField[] $mFlatFields
 
 $mFooter = ''
 
 $mHeader = ''
 
 $mHiddenFields = array()
 
 $mId
 
 $mMessagePrefix
 
 $mMethod = 'post'
 
 $mPost = ''
 
 $mPre = ''
 
 $mSectionFooters = array()
 
 $mSectionHeaders = array()
 
 $mShowReset = false
 
 $mShowSubmit = true
 
 $mSubmitCallback
 
 $mSubmitID
 
 $mSubmitName
 
 $mSubmitText
 
 $mSubmitTooltip
 
 $mSubSectionBeforeFields = true
 If true, sections that contain both fields and subsections will render their subsections before their fields. More...
 
 $mTableId = ''
 
 $mTitle
 
 $mUseMultipart = false
 
 $mValidationErrorMessage
 
 $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 'id' – HTML id attribute 'cssclass' – CSS class 'options' – associative array mapping labels to values. Some field types support multi-level arrays. 'options-messages' – associative array mapping message keys to values. Some field types support multi-level arrays. 'options-message' – message key to be parsed to extract the list of options (like 'ipbreason-dropdown'). 'label-message' – message key 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 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 key. As above, each item can be an array of msg key and then parameters. Overwrites 'help'. '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
HTMLForm::filter() 'validation-callback' – a function name to give you the chance to impose extra validation on the field input.
HTMLForm::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.

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

Example:
$form = new HTMLForm( $someFields );
$form->setMethod( 'get' )
->setWrapperLegendMsg( 'message-key' )
->prepareForm()
->displayForm( '' );
Note that you will have prepareForm and displayForm at the end. Other methods call done after that would simply not be part of the form :(
Todo:
Document 'section' / 'subsection' stuff

Definition at line 100 of file HTMLForm.php.

Constructor & Destructor Documentation

◆ __construct()

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

Build a new HTMLForm from an array of field attributes.

Parameters
array$descriptorof Field constructs, as described above
$contextIContextSource available since 1.18, will become compulsory in 1.18. Obviates the need to call $form->setTitle()
string$messagePrefixa prefix to go in front of default messages

Definition at line 203 of file HTMLForm.php.

References ContextSource\$context, $section, array(), as, isVForm(), loadInputFromParameters(), and ContextSource\setContext().

Member Function Documentation

◆ addButton()

HTMLForm::addButton (   $name,
  $value,
  $id = null,
  $attribs = null 
)

Add a button to the form.

Parameters
string$namefield name.
string$valuefield value
string$idDOM id for the button (default: null)
$attribsArray
Returns
HTMLForm $this for chaining calls (since 1.20)

Definition at line 692 of file HTMLForm.php.

◆ addFooterText()

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

Add footer text, inside the form.

Parameters
string$msgcomplete text of message to display
string$sectionThe section to add the footer text to
Returns
HTMLForm $this for chaining calls (since 1.20)

Definition at line 590 of file HTMLForm.php.

References $section.

◆ addHeaderText()

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

Add header text, inside the form.

Parameters
string$msgcomplete text of message to display
string$sectionThe section to add the header to
Returns
HTMLForm $this for chaining calls (since 1.20)

Definition at line 550 of file HTMLForm.php.

References $section.

Referenced by UploadForm\getDescriptionSection().

◆ addHiddenField()

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

Add a hidden field to the output.

Parameters
string$namefield name. This will be used exactly as entered
string$valuefield value
$attribsArray
Returns
HTMLForm $this for chaining calls (since 1.20)

Definition at line 657 of file HTMLForm.php.

References $attribs, $name, $value, and array().

◆ 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 674 of file HTMLForm.php.

References $name, $value, array(), and as.

◆ addJS()

static HTMLForm::addJS ( )
static

Add the HTMLForm-specific JavaScript, if it hasn't been done already.

Deprecated:
since 1.18 load modules with ResourceLoader instead

Definition at line 306 of file HTMLForm.php.

References wfDeprecated().

◆ 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)

Definition at line 629 of file HTMLForm.php.

◆ addPreText()

HTMLForm::addPreText (   $msg)

Add introductory text.

Parameters
string$msgcomplete text of message to display
Returns
HTMLForm $this for chaining calls (since 1.20)

Definition at line 536 of file HTMLForm.php.

◆ 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.

Attention
You should call prepareForm() before calling this function. Moreover, when doing method chaining this should be the very last method call just after prepareForm().
Parameters
$submitResultMixed output from HTMLForm::trySubmit()
Returns
Nothing, should be last call

Definition at line 710 of file HTMLForm.php.

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

Referenced by show().

◆ displaySection()

HTMLForm::displaySection (   $fields,
  $sectionName = '',
  $fieldsetIDPrefix = '',
$hasUserVisibleFields = false 
)
Todo:
Document
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.
boolean&$hasUserVisibleFieldsWhether the section had user-visible fields.
Returns
String

Definition at line 1169 of file HTMLForm.php.

References $attribs, $displayFormat, $html, $section, $value, array(), as, Sanitizer\escapeId(), Xml\fieldset(), getDisplayFormat(), getLegend(), and Html\rawElement().

Referenced by EditWatchlistNormalHTMLForm\getBody(), getBody(), and PreferencesForm\getBody().

◆ 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.

Parameters
$data
Returns

Reimplemented in PreferencesForm.

Definition at line 1321 of file HTMLForm.php.

Referenced by trySubmit().

◆ formatErrors()

static HTMLForm::formatErrors (   $errors)
static

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

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

Definition at line 932 of file HTMLForm.php.

References $error, array(), as, Html\rawElement(), and wfMessage().

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

◆ getAction()

HTMLForm::getAction ( )

Get the value for the action attribute of the form.

Since
1.22
Returns
string

Definition at line 1360 of file HTMLForm.php.

References $mAction, $wgArticlePath, getMethod(), getTitle(), and global.

Referenced by wrapForm().

◆ getBody()

HTMLForm::getBody ( )

Get the whole body of the form.

Returns
String

Reimplemented in PreferencesForm, and EditWatchlistNormalHTMLForm.

Definition at line 896 of file HTMLForm.php.

References displaySection().

Referenced by getHTML().

◆ getButtons()

HTMLForm::getButtons ( )

Get the submit and (potentially) reset buttons.

Returns
String HTML.

Reimplemented in PreferencesForm.

Definition at line 815 of file HTMLForm.php.

References $attribs, $html, $mSubmitID, $mSubmitName, array(), as, Html\element(), getSubmitText(), isVForm(), ContextSource\msg(), Html\rawElement(), Xml\submitButton(), text, and Linker\tooltipAndAccesskeyAttribs().

Referenced by getHTML().

◆ 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 above
Exceptions
MWException
Returns
string Name of a HTMLFormField subclass

Definition at line 326 of file HTMLForm.php.

Referenced by loadInputFromParameters().

◆ getDisplayFormat()

HTMLForm::getDisplayFormat ( )

Getter for displayFormat.

Since
1.20
Returns
String

Definition at line 288 of file HTMLForm.php.

References $displayFormat.

Referenced by displaySection().

◆ getErrors()

HTMLForm::getErrors (   $errors)

Format and display an error message stack.

Parameters
$errorsString|Array|Status
Returns
String

Definition at line 907 of file HTMLForm.php.

References array(), formatErrors(), ContextSource\getOutput(), and Html\rawElement().

Referenced by getHTML().

◆ getHiddenFields()

HTMLForm::getHiddenFields ( )

Get the hidden fields that should go inside the form.

Returns
String HTML.

Definition at line 786 of file HTMLForm.php.

References $attribs, $html, $value, $wgArticlePath, array(), as, getMethod(), getTitle(), ContextSource\getUser(), global, Html\hidden(), and list.

Referenced by getHTML().

◆ getHTML()

HTMLForm::getHTML (   $submitResult)

Returns the raw HTML generated by the form.

Parameters
$submitResultMixed output from HTMLForm::trySubmit()
Returns
string

Definition at line 721 of file HTMLForm.php.

References $html, $mFooter, $mPost, array(), getBody(), getButtons(), getErrors(), getHiddenFields(), ContextSource\getOutput(), isVForm(), 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.

Parameters
$keyString
Returns
String

Reimplemented in EditWatchlistNormalHTMLForm, and PreferencesForm.

Definition at line 1333 of file HTMLForm.php.

References ContextSource\msg().

Referenced by displaySection().

◆ getMethod()

HTMLForm::getMethod ( )

Definition at line 1152 of file HTMLForm.php.

References $mMethod.

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

◆ getSubmitText()

HTMLForm::getSubmitText ( )

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

Returns
string

Definition at line 986 of file HTMLForm.php.

References ContextSource\msg().

Referenced by getButtons().

◆ getTitle()

HTMLForm::getTitle ( )

Get the title.

Returns
Title

Reimplemented from ContextSource.

Definition at line 1133 of file HTMLForm.php.

References $mTitle, and ContextSource\getContext().

Referenced by getAction(), and getHiddenFields().

◆ isVForm()

HTMLForm::isVForm ( )

Test if displayFormat is 'vform'.

Since
1.22
Returns
Bool

Definition at line 297 of file HTMLForm.php.

Referenced by __construct(), getButtons(), getHTML(), and wrapForm().

◆ loadData()

HTMLForm::loadData ( )

Construct the form fields from the Descriptor array.

Definition at line 1276 of file HTMLForm.php.

References $name, $value, array(), as, and ContextSource\getRequest().

Referenced by prepareForm().

◆ loadInputFromParameters()

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

Initialise a new Object for the field.

Parameters
string$fieldnameName of the field
array$descriptorInput Descriptor, as described above
Exceptions
MWException
Returns
HTMLFormField subclass

Definition at line 351 of file HTMLForm.php.

References getClassFromDescriptor().

Referenced by __construct(), ApiOptions\execute(), and Preferences\getPreferences().

◆ prepareForm()

HTMLForm::prepareForm ( )

Prepare form for submission.

Attention
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 373 of file HTMLForm.php.

References loadData().

Referenced by show().

◆ 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 1347 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 273 of file HTMLForm.php.

◆ setFooterText()

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

Set footer text, inside the form.

Since
1.19
Parameters
string$msgcomplete text of message to display
string$sectionThe section to add the footer text to
Returns
HTMLForm $this for chaining calls (since 1.20)

Definition at line 612 of file HTMLForm.php.

References $section.

◆ setHeaderText()

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

Set header text, inside the form.

Since
1.19
Parameters
string$msgcomplete text of message to display
$sectionThe section to add the header to
Returns
HTMLForm $this for chaining calls (since 1.20)

Definition at line 572 of file HTMLForm.php.

References $section.

Referenced by SpecialChangePassword\alterForm().

◆ setId()

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

Definition at line 1064 of file HTMLForm.php.

Referenced by UploadForm\__construct().

◆ 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)

Definition at line 509 of file HTMLForm.php.

References setPreText().

◆ 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
$pString
Returns
HTMLForm $this for chaining calls (since 1.20)

Definition at line 1110 of file HTMLForm.php.

◆ setMethod()

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

Set the method used to submit the form.

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

Definition at line 1146 of file HTMLForm.php.

Referenced by SpecialRedirect\alterForm().

◆ 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)

Definition at line 642 of file HTMLForm.php.

◆ setPreText()

HTMLForm::setPreText (   $msg)

Set the introductory message, overwriting any existing message.

Since
1.19
Parameters
string$msgcomplete text of message to display
Returns
HTMLForm $this for chaining calls (since 1.20)

Definition at line 523 of file HTMLForm.php.

Referenced by setIntro().

◆ setSubmitCallback()

HTMLForm::setSubmitCallback (   $cb)

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

Parameters
string$cbfunction name. The function will be passed the output from HTMLForm::filterDataForSubmit, and must return Bool true on success, Bool false if no submission was attempted, or String HTML output to display on error.
Returns
HTMLForm $this for chaining calls (since 1.20)

Definition at line 482 of file HTMLForm.php.

◆ setSubmitID()

HTMLForm::setSubmitID (   $t)

Set the id for the submit button.

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

Definition at line 1022 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 997 of file HTMLForm.php.

References $name.

Referenced by UploadForm\__construct().

◆ 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 962 of file HTMLForm.php.

References $t.

Referenced by UploadForm\__construct(), and setSubmitTextMsg().

◆ setSubmitTextMsg()

HTMLForm::setSubmitTextMsg (   $msg)

Set the text for the submit button to a message.

Since
1.19
Parameters
string$msgmessage key
Returns
HTMLForm $this for chaining calls (since 1.20)

Definition at line 976 of file HTMLForm.php.

References ContextSource\msg(), setSubmitText(), and text.

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

◆ setSubmitTooltip()

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

Definition at line 1008 of file HTMLForm.php.

References $name.

Referenced by UploadForm\__construct().

◆ 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 1053 of file HTMLForm.php.

◆ setTitle()

HTMLForm::setTitle (   $t)

Set the title for form submission.

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

Definition at line 1123 of file HTMLForm.php.

References $t.

◆ setValidationErrorMessage()

HTMLForm::setValidationErrorMessage (   $msg)

Set a message to display on a validation error.

Parameters
$msgMixed String or Array of valid inputs to wfMessage() (so each entry can be either a String or Array)
Returns
HTMLForm $this for chaining calls (since 1.20)

Definition at line 496 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 | false$legendHTML to go inside the "<legend>" element, or false for no <legend> Will be escaped
Returns
HTMLForm $this for chaining calls (since 1.20)

Definition at line 1080 of file HTMLForm.php.

Referenced by 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$msgmessage key
Returns
HTMLForm $this for chaining calls (since 1.20)

Definition at line 1095 of file HTMLForm.php.

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

◆ 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.

Returns
Bool or Status whether submission was successful.

Reimplemented in UploadForm.

Definition at line 420 of file HTMLForm.php.

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

◆ 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 1038 of file HTMLForm.php.

◆ 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 1306 of file HTMLForm.php.

◆ tryAuthorizedSubmit()

HTMLForm::tryAuthorizedSubmit ( )

Try submitting, with edit token check first.

Returns
Status|boolean

Definition at line 389 of file HTMLForm.php.

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

Referenced by show().

◆ trySubmit()

HTMLForm::trySubmit ( )

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

Exceptions
MWException
Returns
Mixed Bool true == Successful submission, Bool false == No submission attempted, anything else == Error to display.

Reimplemented in UploadForm.

Definition at line 441 of file HTMLForm.php.

References $mSubmitCallback, $res, array(), as, filterDataForSubmit(), and true.

Referenced by tryAuthorizedSubmit().

◆ wrapForm()

HTMLForm::wrapForm (   $html)

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

Parameters
string$htmlHTML contents to wrap.
Returns
String wrapped HTML.

Reimplemented in PreferencesForm.

Definition at line 754 of file HTMLForm.php.

References $attribs, $html, $mId, array(), Xml\fieldset(), getAction(), getMethod(), isVForm(), and Html\rawElement().

Referenced by getHTML().

Member Data Documentation

◆ $availableDisplayFormats

Array HTMLForm::$availableDisplayFormats
protected
Initial value:
'table',
'div',
'raw',
'vform',
)

Available formats in which to display the form.

Definition at line 188 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 183 of file HTMLForm.php.

Referenced by displaySection(), 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 162 of file HTMLForm.php.

Referenced by getAction().

◆ $mButtons

HTMLForm::$mButtons = array()
protected

Definition at line 166 of file HTMLForm.php.

◆ $mFieldData

HTMLForm::$mFieldData

Definition at line 128 of file HTMLForm.php.

◆ $mFieldTree

HTMLForm::$mFieldTree
protected

Definition at line 134 of file HTMLForm.php.

◆ $mFlatFields

HTMLFormField [] HTMLForm::$mFlatFields
protected

Definition at line 132 of file HTMLForm.php.

◆ $mFooter

HTMLForm::$mFooter = ''
protected

Definition at line 143 of file HTMLForm.php.

Referenced by getHTML().

◆ $mHeader

HTMLForm::$mHeader = ''
protected

Definition at line 142 of file HTMLForm.php.

◆ $mHiddenFields

HTMLForm::$mHiddenFields = array()
protected

Definition at line 165 of file HTMLForm.php.

◆ $mId

HTMLForm::$mId
protected

Definition at line 147 of file HTMLForm.php.

Referenced by wrapForm().

◆ $mMessagePrefix

HTMLForm::$mMessagePrefix
protected

Definition at line 130 of file HTMLForm.php.

◆ $mMethod

HTMLForm::$mMethod = 'post'
protected

Definition at line 156 of file HTMLForm.php.

Referenced by getMethod().

◆ $mPost

HTMLForm::$mPost = ''
protected

Definition at line 146 of file HTMLForm.php.

Referenced by getHTML().

◆ $mPre

HTMLForm::$mPre = ''
protected

Definition at line 141 of file HTMLForm.php.

◆ $mSectionFooters

HTMLForm::$mSectionFooters = array()
protected

Definition at line 145 of file HTMLForm.php.

◆ $mSectionHeaders

HTMLForm::$mSectionHeaders = array()
protected

Definition at line 144 of file HTMLForm.php.

◆ $mShowReset

HTMLForm::$mShowReset = false
protected

Definition at line 135 of file HTMLForm.php.

◆ $mShowSubmit

HTMLForm::$mShowSubmit = true
protected

Definition at line 136 of file HTMLForm.php.

◆ $mSubmitCallback

HTMLForm::$mSubmitCallback
protected

Definition at line 138 of file HTMLForm.php.

Referenced by trySubmit().

◆ $mSubmitID

HTMLForm::$mSubmitID
protected

Definition at line 150 of file HTMLForm.php.

Referenced by getButtons().

◆ $mSubmitName

HTMLForm::$mSubmitName
protected

Definition at line 151 of file HTMLForm.php.

Referenced by getButtons().

◆ $mSubmitText

HTMLForm::$mSubmitText
protected

Definition at line 152 of file HTMLForm.php.

◆ $mSubmitTooltip

HTMLForm::$mSubmitTooltip
protected

Definition at line 153 of file HTMLForm.php.

◆ $mSubSectionBeforeFields

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 177 of file HTMLForm.php.

◆ $mTableId

HTMLForm::$mTableId = ''
protected

Definition at line 148 of file HTMLForm.php.

◆ $mTitle

HTMLForm::$mTitle
protected

Definition at line 155 of file HTMLForm.php.

Referenced by getTitle().

◆ $mUseMultipart

HTMLForm::$mUseMultipart = false
protected

Definition at line 164 of file HTMLForm.php.

◆ $mValidationErrorMessage

HTMLForm::$mValidationErrorMessage
protected

Definition at line 139 of file HTMLForm.php.

◆ $mWrapperLegend

HTMLForm::$mWrapperLegend = false
protected

Definition at line 168 of file HTMLForm.php.

◆ $typeMappings

HTMLForm::$typeMappings
static
Initial value:
'api' => 'HTMLApiField',
'text' => 'HTMLTextField',
'textarea' => 'HTMLTextAreaField',
'select' => 'HTMLSelectField',
'radio' => 'HTMLRadioField',
'multiselect' => 'HTMLMultiSelectField',
'check' => 'HTMLCheckField',
'toggle' => 'HTMLCheckField',
'int' => 'HTMLIntField',
'float' => 'HTMLFloatField',
'info' => 'HTMLInfoField',
'selectorother' => 'HTMLSelectOrOtherField',
'selectandother' => 'HTMLSelectAndOtherField',
'submit' => 'HTMLSubmitField',
'hidden' => 'HTMLHiddenField',
'edittools' => 'HTMLEditTools',
'checkmatrix' => 'HTMLCheckMatrix',
'email' => 'HTMLTextField',
'password' => 'HTMLTextField',
'url' => 'HTMLTextField',
)

Definition at line 102 of file HTMLForm.php.


The documentation for this class was generated from the following file:
$form
usually copyright or history_copyright This message must be in HTML not wikitext $subpages will be ignored and the rest of subPageSubtitle() will run. 'SkinTemplateBuildNavUrlsNav_urlsAfterPermalink' whether MediaWiki currently thinks this is a CSS JS page Hooks may change this value to override the return value of Title::isCssOrJsPage(). 'TitleIsAlwaysKnown' whether MediaWiki currently thinks this page is known isMovable() always returns false. $title whether MediaWiki currently thinks this page is movable Hooks may change this value to override the return value of Title::isMovable(). 'TitleIsWikitextPage' whether MediaWiki currently thinks this is a wikitext page Hooks may change this value to override the return value of Title::isWikitextPage() 'TitleMove' use UploadVerification and UploadVerifyFile instead $form
Definition: hooks.txt:2578
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
HTMLForm
Object handling generic submission, CSRF protection, layout and other logic for UI forms.
Definition: HTMLForm.php:100