Moodle APIs 3.9
Moodle 3.9.13+ (Build: 20220325)
|
Public Member Functions | |
__construct ($formName, $method, $action, $target='', $attributes=null, $ajaxformdata=null) | |
Class constructor - same parameters as HTML_QuickForm_DHTMLRulesTableless. More... | |
_getElNamesRecursive ($element) | |
Get names of element or elements in a group. More... | |
_registerCancelButton ($addfieldsname) | |
Registers a button as cancel button. More... | |
_setDefaultRuleMessages () | |
Sets default error message. | |
accept (&$renderer) | |
Accepts a renderer. More... | |
addAdvancedStatusElement ($headerid, $showmore=false) | |
Use this method to add show more/less status element required for passing over the advanced elements visibility status on the form submission. More... | |
addGroupRule ($group, $arg1, $type='', $format=null, $howmany=0, $validation='server', $reset=false) | |
Adds a validation rule for the given group of elements. More... | |
addHelpButton ($elementname, $identifier, $component='moodle', $linktext='', $suppresscheck=false) | |
Add a help button to element, only one button per element is allowed. More... | |
addRule ($element, $message, $type, $format=null, $validation='server', $reset=false, $force=false) | |
Adds a validation rule for the given field. More... | |
closeHeaderBefore ($elementName) | |
Adds one or more element names that indicate the end of a fieldset. More... | |
disable_form_change_checker () | |
Call this method if you don't want the formchangechecker JavaScript to be automatically initialised for this form. | |
disabledIf ($elementName, $dependentOn, $condition='notchecked', $value='1') | |
Adds a dependency for $elementName which will be disabled if $condition is met. More... | |
enable_form_change_checker () | |
If you have called disable_form_change_checker() then you can use this method to re-enable it. More... | |
exportValues ($elementList=null) | |
export submitted values More... | |
getAdvancedHTML () | |
Returns HTML for advanced elements. More... | |
getCleanedValue ($value, $type) | |
Return the cleaned value using the passed type(s). More... | |
getCleanType ($elementname, $value, $default=PARAM_RAW) | |
Return the type(s) to use to clean an element. More... | |
getLockOptionObject () | |
Get list of attributes which have dependencies. More... | |
getReqHTML () | |
Returns HTML for required elements. More... | |
getShowAdvanced () | |
This function has been deprecated. More... | |
getValidationScript () | |
Returns the client side validation script. More... | |
hardFreeze ($elementList=null) | |
Displays elements without HTML input tags. More... | |
hardFreezeAllVisibleExcept ($elementList) | |
Hard freeze all elements in a form except those whose names are in $elementList or hidden elements in a form. More... | |
hideIf ($elementname, $dependenton, $condition='notchecked', $value='1') | |
Adds a dependency for $elementName which will be hidden if $condition is met. More... | |
is_dirty () | |
Is the form currently set to dirty? More... | |
is_form_change_checker_enabled () | |
is_new_repeat ($name) | |
Check if the element with the given name has just been added by clicking on the 'Add repeating elements' button. More... | |
isNoSubmitButton ($buttonname) | |
Checks if button is a no submit button, i.e it doesn't submit form. More... | |
isSubmitted () | |
Tells whether the form was already submitted. More... | |
MoodleQuickForm ($formName, $method, $action, $target='', $attributes=null) | |
Old syntax of class constructor. More... | |
note_new_repeat ($name) | |
Add the element name to the list of newly-created repeat elements (So that elements that interpret 'no data submitted' as a valid state can tell when they should get the default value instead). More... | |
optional_param ($name, $default, $type) | |
Checks if a parameter was passed in the previous form submission. More... | |
registerNoSubmitButton ($buttonname) | |
Registers button as no submit button. More... | |
set_initial_dirty_state ($state=false) | |
Set the initial 'dirty' state of the form. More... | |
setAdvanced ($elementName, $advanced=true) | |
Use this method to indicate an element in a form is an advanced field. More... | |
setConstant ($elname, $value) | |
Set constant value not overridden by _POST or _GET note: this does not work for complex names with [] :-(. More... | |
setDefault ($elementName, $defaultValue) | |
Initializes a default form value. More... | |
setDisableShortforms ($disable=true) | |
Use this method to indicate that the form will not be using shortforms. More... | |
setExpanded ($headername, $expanded=true, $ignoreuserstate=false) | |
Use this method to indicate that the fieldset should be shown as expanded. More... | |
setForceLtr ($elementname, $value=true) | |
Set an element to be forced to flow LTR. More... | |
setShowAdvanced ($showadvancedNow=null) | |
This function has been deprecated. More... | |
setType ($elementname, $paramtype) | |
Should be used for all elements of a form except for select, radio and checkboxes which clean their own data. More... | |
setTypes ($paramtypes) | |
This can be used to set several types at once. More... | |
updateSubmission ($submission, $files) | |
Updates submitted values. More... | |
Public Attributes | |
array | $_advancedElements = array() |
Array whose keys are element names. More... | |
array | $_cancelButtons =array() |
Array of buttons that if pressed do not result in the processing of the form. | |
array | $_collapsibleElements = array() |
Array whose keys are element names and values are the desired collapsible state. More... | |
array | $_dependencies = array() |
dependent state for the element/'s | |
boolean | $_disableShortforms = false |
Whether to enable shortforms for this form. | |
string | $_formName = '' |
The form name is derived from the class name of the wrapper minus the trailing form It is a name with words joined by underscores whereas the id attribute is words joined by underscores. | |
array | $_noSubmitButtons =array() |
Array of buttons that if pressed do not result in the processing of the form. | |
string | $_pageparams = '' |
String with the html for hidden params passed in as part of a moodle_url object for the action. More... | |
array | $_types = array() |
type (PARAM_INT, PARAM_TEXT etc) of element value | |
const | DEP_DISABLE = 0 |
Is this a 'disableIf' dependency ? | |
const | DEP_HIDE = 1 |
Is this a 'hideIf' dependency? | |
Protected Member Functions | |
prepare_fixed_value ($name, $value) | |
This is a bit of a hack, and it duplicates the code in HTML_QuickForm_element::_prepareValue, but I could not think of a way or reliably calling that code. More... | |
MoodleQuickForm::__construct | ( | $formName, | |
$method, | |||
$action, | |||
$target = '' , |
|||
$attributes = null , |
|||
$ajaxformdata = null |
|||
) |
Class constructor - same parameters as HTML_QuickForm_DHTMLRulesTableless.
@staticvar int $formcounter counts number of forms
string | $formName | Form's name. |
string | $method | Form's method defaults to 'POST' |
string | moodle_url | $action | Form's action |
string | $target | (optional)Form's target defaults to none |
mixed | $attributes | (optional)Extra attributes for <form> tag |
array | $ajaxformdata | Forms submitted via ajax, must pass their data here, instead of relying on _GET and _POST. |
MoodleQuickForm::_getElNamesRecursive | ( | $element | ) |
Get names of element or elements in a group.
HTML_QuickForm_group | element | $element | element group or element object |
array |
MoodleQuickForm::_registerCancelButton | ( | $addfieldsname | ) |
Registers a button as cancel button.
string | $addfieldsname | name of the button |
MoodleQuickForm::accept | ( | & | $renderer | ) |
Accepts a renderer.
HTML_QuickForm_Renderer | $renderer | An HTML_QuickForm_Renderer object |
MoodleQuickForm::addAdvancedStatusElement | ( | $headerid, | |
$showmore = false |
|||
) |
Use this method to add show more/less status element required for passing over the advanced elements visibility status on the form submission.
string | $headerName | header element name. |
boolean | $showmore | default false sets the advanced elements to be hidden. |
MoodleQuickForm::addGroupRule | ( | $group, | |
$arg1, | |||
$type = '' , |
|||
$format = null , |
|||
$howmany = 0 , |
|||
$validation = 'server' , |
|||
$reset = false |
|||
) |
Adds a validation rule for the given group of elements.
Only groups with a name can be assigned a validation rule Use addGroupRule when you need to validate elements inside the group. Use addRule if you need to validate the group as a whole. In this case, the same rule will be applied to all elements in the group. Use addRule if you need to validate the group against a function.
string | $group | Form group name |
array | string | $arg1 | Array for multiple elements or error message string for one element |
string | $type | (optional)Rule type use getRegisteredRules() to get types |
string | $format | (optional)Required for extra rule data |
int | $howmany | (optional)How many valid elements should be in the group |
string | $validation | (optional)Where to perform validation: "server", "client" |
bool | $reset | Client-side: whether to reset the element's value to its original state if validation failed. |
MoodleQuickForm::addHelpButton | ( | $elementname, | |
$identifier, | |||
$component = 'moodle' , |
|||
$linktext = '' , |
|||
$suppresscheck = false |
|||
) |
Add a help button to element, only one button per element is allowed.
This is new, simplified and preferable method of setting a help icon on form elements. It uses the new $OUTPUT->help_icon().
Typically, you will provide the same identifier and the component as you have used for the label of the element. The string identifier with the _help suffix added is then used as the help string.
There has to be two strings defined: 1/ get_string($identifier, $component) - the title of the help page 2/ get_string($identifier.'_help', $component) - the actual help page text
string | $elementname | name of the element to add the item to |
string | $identifier | help string identifier without _help suffix |
string | $component | component name to look the help string in |
string | $linktext | optional text to display next to the icon |
bool | $suppresscheck | set to true if the element may not exist |
MoodleQuickForm::addRule | ( | $element, | |
$message, | |||
$type, | |||
$format = null , |
|||
$validation = 'server' , |
|||
$reset = false , |
|||
$force = false |
|||
) |
Adds a validation rule for the given field.
If the element is in fact a group, it will be considered as a whole. To validate grouped elements as separated entities, use addGroupRule instead of addRule.
string | $element | Form element name |
string | $message | Message to display for invalid data |
string | $type | Rule type, use getRegisteredRules() to get types |
string | $format | (optional)Required for extra rule data |
string | $validation | (optional)Where to perform validation: "server", "client" |
bool | $reset | Client-side validation: reset the form element to its original value if there is an error? |
bool | $force | Force the rule to be applied, even if the target form element does not exist |
MoodleQuickForm::closeHeaderBefore | ( | $elementName | ) |
Adds one or more element names that indicate the end of a fieldset.
string | $elementName | name of the element |
MoodleQuickForm::disabledIf | ( | $elementName, | |
$dependentOn, | |||
$condition = 'notchecked' , |
|||
$value = '1' |
|||
) |
Adds a dependency for $elementName which will be disabled if $condition is met.
If $condition = 'notchecked' (default) then the condition is that the $dependentOn element is not checked. If $condition = 'checked' then the condition is that the $dependentOn element is checked. If $condition is something else (like "eq" for equals) then it is checked to see if the value of the $dependentOn element is $condition (such as equal) to $value.
When working with multiple selects, the dependentOn has to be the real name of the select, meaning that it will most likely end up with '[]'. Also, the value should be an array of required values, or a string containing the values separated by pipes: array('red', 'blue') or 'red|blue'.
string | $elementName | the name of the element which will be disabled |
string | $dependentOn | the name of the element whose state will be checked for condition |
string | $condition | the condition to check |
mixed | $value | used in conjunction with condition. |
MoodleQuickForm::enable_form_change_checker | ( | ) |
If you have called disable_form_change_checker() then you can use this method to re-enable it.
It is enabled by default, so normally you don't need to call this.
MoodleQuickForm::exportValues | ( | $elementList = null | ) |
export submitted values
string | $elementList | list of elements in form |
array |
MoodleQuickForm::getAdvancedHTML | ( | ) |
Returns HTML for advanced elements.
string |
MoodleQuickForm::getCleanedValue | ( | $value, | |
$type | |||
) |
Return the cleaned value using the passed type(s).
mixed | $value | value that has to be cleaned. |
int | array | $type | constant value to use to clean (PARAM_...), typically returned by self::getCleanType(). |
mixed | cleaned up value. |
MoodleQuickForm::getCleanType | ( | $elementname, | |
$value, | |||
$default = PARAM_RAW |
|||
) |
Return the type(s) to use to clean an element.
In the case where the element has an array as a value, we will try to obtain a type defined for that specific key, and recursively until done.
This method does not work reverse, you cannot pass a nested element and hoping to fallback on the clean type of a parent. This method intends to be used with the main element, which will generate child types if needed, not the other way around.
Example scenario:
You have defined a new repeated element containing a text field called 'foo'. By default there will always be 2 occurence of 'foo' in the form. Even though you've set the type on 'foo' to be PARAM_INT, for some obscure reason, you want the first value of 'foo', to be PARAM_FLOAT, which you set using setType: $mform->setType('foo[0]', PARAM_FLOAT).
Now if you call this method passing 'foo', along with the submitted values of 'foo': array(0 => '1.23', 1 => '10'), you will get an array telling you that the key 0 is a FLOAT and 1 is an INT. If you had passed 'foo[1]', along with its value '10', you would get the default clean type returned (param $default).
string | $elementname | name of the element. |
mixed | $value | value that should be cleaned. |
int | $default | default constant value to be returned (PARAM_...) |
string|array | constant value or array of constant values (PARAM_...) |
MoodleQuickForm::getLockOptionObject | ( | ) |
Get list of attributes which have dependencies.
array |
MoodleQuickForm::getReqHTML | ( | ) |
Returns HTML for required elements.
string |
MoodleQuickForm::getShowAdvanced | ( | ) |
This function has been deprecated.
Show advanced has been replaced by "Show more.../Show less..." in the shortforms javascript module.
bool | (Always false) |
MoodleQuickForm::getValidationScript | ( | ) |
Returns the client side validation script.
The code here was copied from HTML_QuickForm_DHTMLRulesTableless who copied it from HTML_QuickForm and slightly modified to run rules per-element Needed to override this because of an error with client side validation of grouped elements.
string | Javascript to perform validation, empty string if no 'client' rules were added |
MoodleQuickForm::hardFreeze | ( | $elementList = null | ) |
Displays elements without HTML input tags.
This method is different to freeze() in that it makes sure no hidden elements are included in the form. Note: If you want to make sure the submitted value is ignored, please use setDefaults().
This function also removes all previously defined rules.
string | array | $elementList | array or string of element(s) to be frozen |
object|bool | if element list is not empty then return error object, else true |
MoodleQuickForm::hardFreezeAllVisibleExcept | ( | $elementList | ) |
Hard freeze all elements in a form except those whose names are in $elementList or hidden elements in a form.
This function also removes all previously defined rules of elements it freezes.
HTML_QuickForm_Error |
array | $elementList | array or string of element(s) not to be frozen |
bool | returns true |
MoodleQuickForm::hideIf | ( | $elementname, | |
$dependenton, | |||
$condition = 'notchecked' , |
|||
$value = '1' |
|||
) |
Adds a dependency for $elementName which will be hidden if $condition is met.
If $condition = 'notchecked' (default) then the condition is that the $dependentOn element is not checked. If $condition = 'checked' then the condition is that the $dependentOn element is checked. If $condition is something else (like "eq" for equals) then it is checked to see if the value of the $dependentOn element is $condition (such as equal) to $value.
When working with multiple selects, the dependentOn has to be the real name of the select, meaning that it will most likely end up with '[]'. Also, the value should be an array of required values, or a string containing the values separated by pipes: array('red', 'blue') or 'red|blue'.
string | $elementname | the name of the element which will be hidden |
string | $dependenton | the name of the element whose state will be checked for condition |
string | $condition | the condition to check |
mixed | $value | used in conjunction with condition. |
MoodleQuickForm::is_dirty | ( | ) |
Is the form currently set to dirty?
boolean | Initial dirty state. |
MoodleQuickForm::is_form_change_checker_enabled | ( | ) |
bool | whether this form should automatically initialise formchangechecker for itself. |
MoodleQuickForm::is_new_repeat | ( | $name | ) |
Check if the element with the given name has just been added by clicking on the 'Add repeating elements' button.
string | $name | the name of the element being checked |
bool | true if the element is newly added |
MoodleQuickForm::isNoSubmitButton | ( | $buttonname | ) |
Checks if button is a no submit button, i.e it doesn't submit form.
string | $buttonname | name of the button to check |
bool |
MoodleQuickForm::isSubmitted | ( | ) |
Tells whether the form was already submitted.
This is useful since the _submitFiles and _submitValues arrays may be completely empty after the trackSubmit value is removed.
bool |
MoodleQuickForm::MoodleQuickForm | ( | $formName, | |
$method, | |||
$action, | |||
$target = '' , |
|||
$attributes = null |
|||
) |
MoodleQuickForm::note_new_repeat | ( | $name | ) |
Add the element name to the list of newly-created repeat elements (So that elements that interpret 'no data submitted' as a valid state can tell when they should get the default value instead).
string | $name | the name of the new element |
MoodleQuickForm::optional_param | ( | $name, | |
$default, | |||
$type | |||
) |
Checks if a parameter was passed in the previous form submission.
string | $name | the name of the page parameter we want |
mixed | $default | the default value to return if nothing is found |
string | $type | expected type of parameter |
mixed |
|
protected |
This is a bit of a hack, and it duplicates the code in HTML_QuickForm_element::_prepareValue, but I could not think of a way or reliably calling that code.
(Think about date selectors, for example.)
string | $name | the element name. |
mixed | $value | the fixed value to set. |
mixed | the appropriate array to add to the $unfiltered array. |
MoodleQuickForm::registerNoSubmitButton | ( | $buttonname | ) |
Registers button as no submit button.
string | $buttonname | name of the button |
MoodleQuickForm::set_initial_dirty_state | ( | $state = false | ) |
Set the initial 'dirty' state of the form.
bool | $state |
MoodleQuickForm::setAdvanced | ( | $elementName, | |
$advanced = true |
|||
) |
Use this method to indicate an element in a form is an advanced field.
If items in a form are marked as advanced then 'Hide/Show Advanced' buttons will automatically be displayed in the form so the user can decide whether to display advanced form controls.
If you set a header element to advanced then all elements it contains will also be set as advanced.
string | $elementName | group or element name (not the element name of something inside a group). |
bool | $advanced | default true sets the element to advanced. False removes advanced mark. |
MoodleQuickForm::setConstant | ( | $elname, | |
$value | |||
) |
Set constant value not overridden by _POST or _GET note: this does not work for complex names with [] :-(.
string | $elname | name of element |
mixed | $value |
MoodleQuickForm::setDefault | ( | $elementName, | |
$defaultValue | |||
) |
Initializes a default form value.
Used to specify the default for a new entry where no data is loaded in using moodleform::set_data()
note: $slashed param removed
string | $elementName | element name |
mixed | $defaultValue | values for that element name |
MoodleQuickForm::setDisableShortforms | ( | $disable = true | ) |
Use this method to indicate that the form will not be using shortforms.
boolean | $disable | default true, controls if the shortforms are disabled. |
MoodleQuickForm::setExpanded | ( | $headername, | |
$expanded = true , |
|||
$ignoreuserstate = false |
|||
) |
Use this method to indicate that the fieldset should be shown as expanded.
The method is applicable to header elements only.
string | $headername | header element name |
boolean | $expanded | default true sets the element to expanded. False makes the element collapsed. |
boolean | $ignoreuserstate | override the state regardless of the state it was on when the form was submitted. |
void |
MoodleQuickForm::setForceLtr | ( | $elementname, | |
$value = true |
|||
) |
Set an element to be forced to flow LTR.
The element must exist and support this functionality. Also note that when setting the type of a field (} we try to guess the whether the field should be force to LTR or not. Make sure you're always calling this method last. string $elementname The element name. bool $value When false, disables force LTR, else enables it.
MoodleQuickForm::setShowAdvanced | ( | $showadvancedNow = null | ) |
This function has been deprecated.
Show advanced has been replaced by "Show more.../Show less..." in the shortforms javascript module.
bool | $showadvancedNow | if true will show advanced elements. |
MoodleQuickForm::setType | ( | $elementname, | |
$paramtype | |||
) |
Should be used for all elements of a form except for select, radio and checkboxes which clean their own data.
string | $elementname | |
int | $paramtype | defines type of data contained in element. Use the constants PARAM_*. lib/moodlelib.php for defined parameter types |
MoodleQuickForm::setTypes | ( | $paramtypes | ) |
This can be used to set several types at once.
array | $paramtypes | types of parameters. |
MoodleQuickForm::updateSubmission | ( | $submission, | |
$files | |||
) |
Updates submitted values.
array | $submission | submitted values |
array | $files | list of files |
array MoodleQuickForm::$_advancedElements = array() |
Array whose keys are element names.
If the key exists this is a advanced element
array MoodleQuickForm::$_collapsibleElements = array() |
Array whose keys are element names and values are the desired collapsible state.
True for collapsed, False for expanded. If not present, set to default in self::accept().
string MoodleQuickForm::$_pageparams = '' |
String with the html for hidden params passed in as part of a moodle_url object for the action.
Output in the form.