Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.3.x will end 7 October 2024 (12 months).
  • Bug fixes for security issues in 4.3.x will end 21 April 2025 (18 months).
  • PHP version: minimum PHP 8.0.0 Note: minimum PHP version has increased since Moodle 4.1. PHP 8.2.x is supported too.

Differences Between: [Versions 310 and 403] [Versions 311 and 403] [Versions 39 and 403] [Versions 400 and 403] [Versions 401 and 403]

select type form element Class to dynamically create an HTML SELECT with all options grouped in optgroups

Copyright: 2007 Jamie Pratt <me@jamiep.org>
License: http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
File Size: 570 lines (19 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 1 file
 lib/form/templatable_form_element.php

Defines 2 classes

MoodleQuickForm_selectgroups:: (2 methods):
  __construct()
  MoodleQuickForm_selectgroups()

name:: (23 methods):
  setSelected()
  getSelected()
  setName()
  getName()
  getPrivateName()
  setValue()
  getValue()
  setSize()
  getSize()
  setMultiple()
  getMultiple()
  loadArrayOptGroups()
  addOptGroup()
  loadArrayOptions()
  addOption()
  toHtml()
  getFrozenHtml()
  exportValue()
  onQuickFormEvent()
  setHiddenLabel()
  getHelpButton()
  getElementTemplateType()
  export_for_template()


Class: MoodleQuickForm_selectgroups  - X-Ref

select type form element

Class to dynamically create an HTML SELECT with all options grouped in optgroups

__construct($elementName=null, $elementLabel=null, $optgrps=null, $attributes=null, $showchoose=false)   X-Ref
Class constructor

param: string $elementName Select name attribute
param: mixed $elementLabel Label(s) for the select
param: array $optgrps Data to be used to populate options
param: mixed $attributes Either a typical HTML attribute string or an associative array
param: bool $showchoose add standard moodle "Choose..." option as first item

MoodleQuickForm_selectgroups($elementName=null, $elementLabel=null, $optgrps=null, $attributes=null, $showchoose=false)   X-Ref
Old syntax of class constructor. Deprecated in PHP7.


Class: name  - X-Ref

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

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

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

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 $value Array or comma delimited string of selected values

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

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

getMultiple()   X-Ref
Returns the select mutiple attribute

return: bool true if multiple select, false otherwise

loadArrayOptGroups($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|bool on error or true

addOptGroup($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

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

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

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

param: string $optgroup name of the option group
param: string $text Display text for the OPTION
param: string $value Value for the OPTION
param: mixed $attributes Either a typical HTML attribute string

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"

param: array $submitValues submitted values
param: bool $assoc if true the retured value is associated array
return: mixed

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: bool

setHiddenLabel($hiddenLabel)   X-Ref
Sets label to be hidden

param: bool $hiddenLabel sets if label should be hidden

getHelpButton()   X-Ref
get html for help button

return: string html for help button

getElementTemplateType()   X-Ref
Slightly different container template when frozen. Don't want to use a label tag
with a for attribute in that case for the element label but instead use a div.
Templates are defined in renderer constructor.

return: string

export_for_template(renderer_base $output)   X-Ref
No description