Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.

Differences Between: [Versions 401 and 402] [Versions 401 and 403]

(no description)

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

Defines 2 classes

HTML_QuickForm_select:: (2 methods):
  __construct()
  HTML_QuickForm_select()

name:: (21 methods):
  apiVersion()
  setSelected()
  getSelected()
  setName()
  getName()
  getPrivateName()
  setValue()
  getValue()
  setSize()
  getSize()
  setMultiple()
  getMultiple()
  addOption()
  loadArray()
  loadDbResult()
  loadQuery()
  load()
  toHtml()
  getFrozenHtml()
  exportValue()
  onQuickFormEvent()


Class: HTML_QuickForm_select  - X-Ref

Class to dynamically create an HTML SELECT

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

param: string    Select name attribute
param: mixed     Label(s) for the select
param: mixed     Data to be used to populate options
param: mixed     Either a typical HTML attribute string or an associative array
return: void

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


Class: name  - X-Ref

apiVersion()   X-Ref
Returns the current API version

return: double

setSelected($values)   X-Ref
Sets the default values of the select box

param: mixed    $values  Array or comma delimited string of selected values
return: void

getSelected()   X-Ref
Returns an array of the selected values

return: array of selected values

setName($name)   X-Ref
Sets the input field name

param: string    $name   Input field name attribute
return: void

getName()   X-Ref
Returns the element name

return: string

getPrivateName()   X-Ref
Returns the element name (possibly with brackets appended)

return: string

setValue($value)   X-Ref
Sets the value of the form element

param: mixed    $values  Array or comma delimited string of selected values
return: void

getValue()   X-Ref
Returns an array of the selected values

return: array of selected values

setSize($size)   X-Ref
Sets the select field size, only applies to 'multiple' selects

param: int    $size  Size of select  field
return: void

getSize()   X-Ref
Returns the select field size

return: int

setMultiple($multiple)   X-Ref
Sets the select mutiple attribute

param: bool    $multiple  Whether the select supports multi-selections
return: void

getMultiple()   X-Ref
Returns the select mutiple attribute

return: bool    true if multiple select, false otherwise

addOption($text, $value, $attributes=null)   X-Ref
Adds a new OPTION to the SELECT

param: string    $text       Display text for the OPTION
param: string    $value      Value for the OPTION
param: mixed     $attributes Either a typical HTML attribute string
return: void

loadArray($arr, $values=null)   X-Ref
Loads the options from an associative array

param: array    $arr     Associative array of options
param: mixed    $values  (optional) Array or comma delimited string of selected values
return: PEAR_Error on error or true

loadDbResult(&$result, $textCol=null, $valueCol=null, $values=null)   X-Ref
Loads the options from DB_result object

If no column names are specified the first two columns of the result are
used as the text and value columns respectively
param: object    $result     DB_result object
param: string    $textCol    (optional) Name of column to display as the OPTION text
param: string    $valueCol   (optional) Name of column to use as the OPTION value
param: mixed     $values     (optional) Array or comma delimited string of selected values
return: PEAR_Error on error or true

loadQuery(&$conn, $sql, $textCol=null, $valueCol=null, $values=null)   X-Ref
Queries a database and loads the options from the results

param: mixed     $conn       Either an existing DB connection or a valid dsn
param: string    $sql        SQL query string
param: string    $textCol    (optional) Name of column to display as the OPTION text
param: string    $valueCol   (optional) Name of column to use as the OPTION value
param: mixed     $values     (optional) Array or comma delimited string of selected values
return: void

load(&$options, $param1=null, $param2=null, $param3=null, $param4=null)   X-Ref
Loads options from different types of data sources

This method is a simulated overloaded method.  The arguments, other than the
first are optional and only mean something depending on the type of the first argument.
If the first argument is an array then all arguments are passed in order to loadArray.
If the first argument is a db_result then all arguments are passed in order to loadDbResult.
If the first argument is a string or a DB connection then all arguments are
passed in order to loadQuery.
param: mixed     $options     Options source currently supports assoc array or DB_result
param: mixed     $param1     (optional) See function detail
param: mixed     $param2     (optional) See function detail
param: mixed     $param3     (optional) See function detail
param: mixed     $param4     (optional) See function detail
return: PEAR_Error on error or true

toHtml()   X-Ref
Returns the SELECT in HTML

return: string

getFrozenHtml()   X-Ref
Returns the value of field without HTML tags

return: string

exportValue(&$submitValues, $assoc = false)   X-Ref
We check the options and return only the values that _could_ have been
selected. We also return a scalar value if select is not "multiple"


onQuickFormEvent($event, $arg, &$caller)   X-Ref
No description