Form elements can be marked as 'advanced'. This has the effect that they are hidden initially.
To control whether an element is advanced, you can use the
setAdvanced method on the MoodleQuickForm instance and set a specific element as being advanced, for example:
It is also possible to unset the advanced status of a field - the
setAdvanced function takes a second, boolean, parameter which defaults to
true. By passing a
false value, the element's advanced flag will be removed, for example:
// Mark a field as not advanced after it was previously marked as advanced.
You should be careful about marking too many elements as advanced.
For more information on the risks of this, see the advice in Designing usable forms.
Whenever you mark a form element as advanced, then the Show / hide advanced links are shown automatically at relevant points within the form.
The Show advanced and Hide advanced links are currently displayed at the top right of all fieldsets containing advanced controls.
Setting a name
When adding a header element, the second parameter to
addElement() is a name field. You should pass a unique name for each header.
If the name is not specified, or is not unique then this can have a range of unintended impacts, including marking multiple sections of the form as advanced. It is strongly encouraged to always name headers.
Marking an entire section as advanced
setAdvanced function can mark an entire section as advanced by specifying the name of the header at the top of the section, for example:
In this example, all fields from this header until the next header will be marked as advanced.