Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 3.9.x will end* 10 May 2021 (12 months).
  • Bug fixes for security issues in 3.9.x will end* 8 May 2023 (36 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.

(no description)

File Size: 286 lines (9 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 2 classes

HTML_QuickForm_advcheckbox:: (2 methods):
  __construct()
  HTML_QuickForm_advcheckbox()

name:: (9 methods):
  getPrivateName()
  getOnclickJs()
  setValues()
  setValue()
  getValue()
  toHtml()
  getFrozenHtml()
  onQuickFormEvent()
  exportValue()


Class: HTML_QuickForm_advcheckbox  - X-Ref

HTML class for an advanced checkbox type field

Basically this fixes a problem that HTML has had
where checkboxes can only pass a single value (the
value of the checkbox when checked).  A value for when
the checkbox is not checked cannot be passed, and
furthermore the checkbox variable doesn't even exist if
the checkbox was submitted unchecked.

It works by prepending a hidden field with the same name and
another "unchecked" value to the checbox. If the checkbox is
checked, PHP overwrites the value of the hidden field with
its value.

__construct($elementName=null, $elementLabel=null, $text=null, $attributes=null, $values=null)   X-Ref
Class constructor

param: string    $elementName    (optional)Input field name attribute
param: string    $elementLabel   (optional)Input field label
param: string    $text           (optional)Text to put after the checkbox
param: mixed     $attributes     (optional)Either a typical HTML attribute string
param: mixed     $values         (optional)Values to pass if checked or not checked
return: void

HTML_QuickForm_advcheckbox($elementName=null, $elementLabel=null, $text=null, $attributes=null, $values=null)   X-Ref
Old syntax of class constructor. Deprecated in PHP7.


Class: name  - X-Ref

getPrivateName($elementName)   X-Ref
Gets the private name for the element

param: string  $elementName The element name to make private
return: string

getOnclickJs($elementName)   X-Ref
Create the javascript for the onclick event which will
set the value of the hidden field

param: string    $elementName    The element name
return: string

setValues($values)   X-Ref
Sets the values used by the hidden element

param: mixed   $values The values, either a string or an array
return: void

setValue($value)   X-Ref
Sets the element's value

param: mixed   Element's value

getValue()   X-Ref
Returns the element's value

return: mixed

toHtml()   X-Ref
Returns the checkbox element in HTML
and the additional hidden element in HTML

return: string

getFrozenHtml()   X-Ref
Unlike checkbox, this has to append a hidden input in both
checked and non-checked states


onQuickFormEvent($event, $arg, &$caller)   X-Ref
Called by HTML_QuickForm whenever form event is made on this element

param: string    $event  Name of event
param: mixed     $arg    event arguments
param: object    $caller calling object
return: void

exportValue(&$submitValues, $assoc = false)   X-Ref
This element has a value even if it is not checked, thus we override
checkbox's behaviour here