MediaWiki  REL1_24
HTMLFormField Class Reference

The parent class to generate form fields. More...

Inheritance diagram for HTMLFormField:
Collaboration diagram for HTMLFormField:

List of all members.

Public Member Functions

 __construct ($params)
 Initialise the object.
 cancelSubmit ($value, $alldata)
 Override this function if the control can somehow trigger a form submission that shouldn't actually submit the HTMLForm.
 filter ($value, $alldata)
 getAttributes (array $list)
 Returns the given attributes from the parameters.
 getDefault ()
 getDiv ($value)
 Get the complete div for the input, including help text, labels, and whatever.
 getErrorsAndErrorClass ($value)
 Determine form errors to display and their classes.
 getHelpText ()
 Determine the help text to display.
 getHelpTextHtmlDiv ($helptext)
 Generate help text HTML in div format.
 getHelpTextHtmlRaw ($helptext)
 Generate help text HTML formatted for raw output.
 getHelpTextHtmlTable ($helptext)
 Generate help text HTML in table format.
 getInputHTML ($value)
 This function must be implemented to return the HTML to generate the input object itself.
 getLabel ()
 getLabelHtml ($cellAttributes=array())
 getOptions ()
 Fetch the array of options from the field's parameters.
 getRaw ($value)
 Get the complete raw fields for the input, including help text, labels, and whatever.
 getTableRow ($value)
 Get the complete table row for the input, including help text, labels, and whatever.
 getTooltipAndAccessKey ()
 Returns the attributes required for the tooltip and accesskey.
 isHidden ($alldata)
 Test whether this field is supposed to be hidden, based on the values of the other form fields.
 loadDataFromRequest ($request)
 Get the value that this input has been set to from a posted form, or the input's default value if it has not been set.
 msg ()
 Get a translated interface message.
 setShowEmptyLabel ($show)
 Tell the field whether to generate a separate label element if its label is blank.
 validate ($value, $alldata)
 Override this function to add specific validation checks on the field input.

Static Public Member Functions

static flattenOptions ($options)
 flatten an array of options to a single array, for instance, a set of "<options>" inside "<optgroups>".
static forceToStringRecursive ($array)
 Recursively forces values in an array to strings, because issues arise with integer 0 as a value.

Public Attributes

 $mParams
HTMLForm $mParent

Protected Member Functions

 getNearestFieldByName ($alldata, $name)
 Fetch a field value from $alldata for the closest field matching a given name.
 isHiddenRecurse (array $alldata, array $params)
 Helper function for isHidden to handle recursive data structures.
 needsLabel ()
 Should this field have a label, or is there no input element with the appropriate id for the label to point to?

Static Protected Member Functions

static formatErrors ($errors)
 Formats one or more errors as accepted by field validation-callback.

Protected Attributes

 $mClass = ''
 $mDefault
 $mFilterCallback
 $mHelpClass = false
 $mHideIf = null
 $mID
 $mLabel
 $mName
 $mOptions = false
 $mOptionsLabelsNotFromMessage = false
bool $mShowEmptyLabels = true
 If true will generate an empty div element with no label.
 $mValidationCallback

Private Member Functions

 lookupOptionsKeys ($options)
 Given an array of msg-key => value mappings, returns an array with keys being the message texts.

Detailed Description

The parent class to generate form fields.

Any field type should be a subclass of this.

Definition at line 7 of file HTMLFormField.php.


Constructor & Destructor Documentation

Initialise the object.

Parameters:
array$paramsAssociative Array. See HTMLForm doc for syntax.
Since:
1.22 The 'label' attribute no longer accepts raw HTML, use 'label-raw' instead
Exceptions:
MWException

Reimplemented in HTMLFormFieldCloner, Licenses, HTMLCheckMatrix, HTMLAutoCompleteSelectField, HTMLSelectAndOtherField, HTMLButtonField, HTMLInfoField, HTMLSelectOrOtherField, and HTMLHiddenField.

Definition at line 341 of file HTMLFormField.php.


Member Function Documentation

HTMLFormField::cancelSubmit ( value,
alldata 
)

Override this function if the control can somehow trigger a form submission that shouldn't actually submit the HTMLForm.

Since:
1.23
Parameters:
string | array$valueThe value the field was submitted with
array$alldataThe data collected from the form
Returns:
bool True to cancel the submission

Reimplemented in HTMLFormFieldCloner.

Definition at line 253 of file HTMLFormField.php.

HTMLFormField::filter ( value,
alldata 
)

Definition at line 287 of file HTMLFormField.php.

static HTMLFormField::flattenOptions ( options) [static]

flatten an array of options to a single array, for instance, a set of "<options>" inside "<optgroups>".

Parameters:
array$optionsAssociative Array with values either Strings or Arrays
Returns:
array Flattened input

Definition at line 846 of file HTMLFormField.php.

Referenced by HTMLSelectAndOtherField\__construct(), Preferences\datetimePreferences(), HTMLMultiSelectField\filterDataForSubmit(), HTMLCheckMatrix\filterDataForSubmit(), HTMLSelectOrOtherField\getInputHTML(), HTMLAutoCompleteSelectField\getInputHTML(), Preferences\getOptionFromUser(), HTMLRadioField\validate(), HTMLSelectField\validate(), HTMLMultiSelectField\validate(), and HTMLAutoCompleteSelectField\validate().

static HTMLFormField::forceToStringRecursive ( array) [static]

Recursively forces values in an array to strings, because issues arise with integer 0 as a value.

Parameters:
array$array
Returns:
array

Definition at line 782 of file HTMLFormField.php.

Referenced by HTMLMultiSelectField\filterDataForSubmit(), and HTMLMultiSelectField\getInputHTML().

static HTMLFormField::formatErrors ( errors) [static, protected]

Formats one or more errors as accepted by field validation-callback.

Parameters:
string | Message | array$errorsArray of strings or Message instances
Returns:
string HTML
Since:
1.18

Definition at line 867 of file HTMLFormField.php.

HTMLFormField::getDiv ( value)

Get the complete div for the input, including help text, labels, and whatever.

Since:
1.20
Parameters:
string$valueThe value to set the input to.
Returns:
string Complete HTML table row.

Reimplemented in HTMLInfoField, HTMLHiddenField, HTMLEditTools, and HTMLApiField.

Definition at line 490 of file HTMLFormField.php.

Determine form errors to display and their classes.

Since:
1.20
Parameters:
string$valueThe value of the input
Returns:
array

Definition at line 657 of file HTMLFormField.php.

Referenced by HTMLCheckMatrix\getTableRow().

Determine the help text to display.

Since:
1.20
Returns:
string

Definition at line 622 of file HTMLFormField.php.

Referenced by HTMLCheckMatrix\getTableRow().

Generate help text HTML in div format.

Since:
1.20
Parameters:
string | null$helptext
Returns:
string

Definition at line 586 of file HTMLFormField.php.

Generate help text HTML formatted for raw output.

Since:
1.20
Parameters:
string | null$helptext
Returns:
string

Definition at line 613 of file HTMLFormField.php.

Generate help text HTML in table format.

Since:
1.20
Parameters:
string | null$helptext
Returns:
string

Definition at line 557 of file HTMLFormField.php.

Referenced by HTMLCheckMatrix\getTableRow().

HTMLFormField::getInputHTML ( value) [abstract]

This function must be implemented to return the HTML to generate the input object itself.

It should not implement the surrounding table cells/rows, or labels/help messages.

Parameters:
string$valueThe value to set the input to; eg a default text for a text input.
Returns:
string Valid HTML.

Reimplemented in HTMLFormFieldCloner, Licenses, HTMLAutoCompleteSelectField, HTMLCheckMatrix, HTMLHiddenField, HTMLSelectAndOtherField, HTMLRadioField, HTMLMultiSelectField, HTMLSelectField, HTMLSelectOrOtherField, HTMLButtonField, HTMLApiField, HTMLTextAreaField, HTMLInfoField, HTMLTextField, HTMLCheckField, and HTMLEditTools.

Reimplemented in HTMLCheckField.

Definition at line 671 of file HTMLFormField.php.

HTMLFormField::getLabelHtml ( cellAttributes = array())

Reimplemented in UploadSourceField.

Definition at line 675 of file HTMLFormField.php.

Referenced by HTMLCheckMatrix\getTableRow().

HTMLFormField::getNearestFieldByName ( alldata,
name 
) [protected]

Fetch a field value from $alldata for the closest field matching a given name.

This is complex because it needs to handle array fields like the user would expect. The general algorithm is to look for $name as a sibling of $this, then a sibling of $this's parent, and so on. Keeping in mind that $name itself might be referencing an array.

Parameters:
array$alldata
string$name
Returns:
string

Definition at line 79 of file HTMLFormField.php.

HTMLFormField::getRaw ( value)

Get the complete raw fields for the input, including help text, labels, and whatever.

Since:
1.20
Parameters:
string$valueThe value to set the input to.
Returns:
string Complete HTML table row.

Reimplemented in HTMLInfoField, HTMLHiddenField, HTMLEditTools, and HTMLApiField.

Definition at line 535 of file HTMLFormField.php.

Get the complete table row for the input, including help text, labels, and whatever.

Parameters:
string$valueThe value to set the input to.
Returns:
string Complete HTML table row.

Reimplemented in HTMLCheckMatrix, HTMLInfoField, HTMLHiddenField, HTMLEditTools, and HTMLApiField.

Definition at line 432 of file HTMLFormField.php.

Returns the attributes required for the tooltip and accesskey.

Returns:
array Attributes

Definition at line 725 of file HTMLFormField.php.

Referenced by HTMLCheckField\getInputHTML(), HTMLTextField\getInputHTML(), and HTMLTextAreaField\getInputHTML().

HTMLFormField::isHidden ( alldata)

Test whether this field is supposed to be hidden, based on the values of the other form fields.

Since:
1.23
Parameters:
array$alldataThe data collected from the form
Returns:
bool

Definition at line 235 of file HTMLFormField.php.

HTMLFormField::isHiddenRecurse ( array alldata,
array params 
) [protected]

Helper function for isHidden to handle recursive data structures.

Parameters:
array$alldata
array$params
Returns:
bool

Definition at line 128 of file HTMLFormField.php.

Get the value that this input has been set to from a posted form, or the input's default value if it has not been set.

Parameters:
WebRequest$request
Returns:
string The value

Reimplemented in HTMLCheckMatrix, HTMLFormFieldCloner, HTMLMultiSelectField, HTMLSelectOrOtherField, HTMLCheckField, HTMLSelectAndOtherField, and HTMLAutoCompleteSelectField.

Definition at line 325 of file HTMLFormField.php.

HTMLFormField::lookupOptionsKeys ( options) [private]

Given an array of msg-key => value mappings, returns an array with keys being the message texts.

It also forces values to strings.

Parameters:
array$options
Returns:
array

Definition at line 764 of file HTMLFormField.php.

HTMLFormField::needsLabel ( ) [protected]

Should this field have a label, or is there no input element with the appropriate id for the label to point to?

Returns:
bool True to output a label, false to suppress

Reimplemented in HTMLFormFieldCloner, HTMLMultiSelectField, HTMLRadioField, HTMLCheckField, HTMLInfoField, and HTMLButtonField.

Definition at line 301 of file HTMLFormField.php.

Tell the field whether to generate a separate label element if its label is blank.

Since:
1.22
Parameters:
bool$showSet to false to not generate a label.
Returns:
void

Definition at line 314 of file HTMLFormField.php.

HTMLFormField::validate ( value,
alldata 
)

Override this function to add specific validation checks on the field input.

Don't forget to call parent::validate() to ensure that the user-defined callback mValidationCallback is still run

Parameters:
string | array$valueThe value the field was submitted with
array$alldataThe data collected from the form
Returns:
bool|string True on success, or String error to display, or false to fail validation without displaying an error.

Reimplemented in EditWatchlistCheckboxSeriesField, HTMLFormFieldCloner, HTMLSelectAndOtherField, HTMLAutoCompleteSelectField, HTMLCheckMatrix, HTMLButtonField, HTMLSelectLimitField, HTMLFloatField, HTMLIntField, HTMLMultiSelectField, HTMLRadioField, and HTMLSelectField.

Definition at line 268 of file HTMLFormField.php.

Referenced by HtmlCheckMatrixTest\validate().


Member Data Documentation

HTMLFormField::$mClass = '' [protected]

Definition at line 15 of file HTMLFormField.php.

HTMLFormField::$mDefault [protected]

Definition at line 17 of file HTMLFormField.php.

HTMLFormField::$mFilterCallback [protected]

Definition at line 11 of file HTMLFormField.php.

HTMLFormField::$mHelpClass = false [protected]

Definition at line 16 of file HTMLFormField.php.

HTMLFormField::$mHideIf = null [protected]

Definition at line 20 of file HTMLFormField.php.

HTMLFormField::$mID [protected]

Definition at line 14 of file HTMLFormField.php.

HTMLFormField::$mLabel [protected]

Definition at line 13 of file HTMLFormField.php.

HTMLFormField::$mName [protected]

Definition at line 12 of file HTMLFormField.php.

HTMLFormField::$mOptions = false [protected]

Definition at line 18 of file HTMLFormField.php.

HTMLFormField::$mOptionsLabelsNotFromMessage = false [protected]

Definition at line 19 of file HTMLFormField.php.

HTMLFormField::$mParams

Definition at line 8 of file HTMLFormField.php.

HTMLForm HTMLFormField::$mParent

Definition at line 29 of file HTMLFormField.php.

bool HTMLFormField::$mShowEmptyLabels = true [protected]

If true will generate an empty div element with no label.

Since:
1.22

Definition at line 25 of file HTMLFormField.php.

HTMLFormField::$mValidationCallback [protected]

Definition at line 10 of file HTMLFormField.php.


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