Note:

If you want to create a new page for developers, you should create it on the Moodle Developer Resource site.

lib/formslib.php setAdvanced: Difference between revisions

From MoodleDocs
mNo edit summary
(One intermediate revision by the same user not shown)
Line 11: Line 11:


setAdvanced takes a second boolean parameter which defaults to true. True means set this control as an advanced control. False means it is not advanced.
setAdvanced takes a second boolean parameter which defaults to true. True means set this control as an advanced control. False means it is not advanced.
===Make Sure You Name the Header of a Fieldset Within Which You Include Advanced Elements===
Ie. this is not good :
<code>
        $mform->addElement('header', <nowiki>''</nowiki>, get_string('miscellaneoussettings', 'form'));
        $mform->addElement('select', 'display', get_string('displaymode', 'choice'), $CHOICE_DISPLAY);
        $mform->setAdvanced('display');
</code>
The second param of the addElement('header', ....) should be a unique name for the header.
If you don't then other sections of the form that also have an unnamed header may also get marked as advanced. This will also happen if header elements have identical names.
==setAdvanced to specify all form elements in a fieldset are advanced elements==
==setAdvanced to specify all form elements in a fieldset are advanced elements==
<code>
<code>

Revision as of 05:51, 13 March 2007

setAdvanced to specify one form element as an advanced option

You can use MoodleQuickForm's method setAdvanced to specify a form element as an advanced option :

       $mform->addElement('select', 'display', get_string('displaymode', 'choice'), $CHOICE_DISPLAY);
       $mform->setAdvanced('display');

If you set any element in a form to be an advanced item then 'show / hide advanced' buttons are shown automatically in the form. Show / hide buttons are currently displayed at the top right of all fieldsets containing advanced controls. The show / hide button shows or hides advanced controls using javascript or if no javascript is available then the whole page is submitted and redisplayed with advanced controls hidden or shown.

setAdvanced takes a second boolean parameter which defaults to true. True means set this control as an advanced control. False means it is not advanced.

Make Sure You Name the Header of a Fieldset Within Which You Include Advanced Elements

Ie. this is not good :

       $mform->addElement('header', '', get_string('miscellaneoussettings', 'form'));
       $mform->addElement('select', 'display', get_string('displaymode', 'choice'), $CHOICE_DISPLAY);
       $mform->setAdvanced('display');

The second param of the addElement('header', ....) should be a unique name for the header.

If you don't then other sections of the form that also have an unnamed header may also get marked as advanced. This will also happen if header elements have identical names.

setAdvanced to specify all form elements in a fieldset are advanced elements

       $mform->addElement('header', 'miscellaneoussettingshdr', get_string('miscellaneoussettings', 'form'));
       $mform->setAdvanced('miscellaneoussettingshdr');

Will set the header element miscellaneoussettingshdr and all the elements it contains to advanced.

What happens when a form is submitted with form elements hidden?

If form elements are hidden and the form is submitted then no values are submitted by the form elements. But the 'default values' of the form elements are automatically passed to the processing functions from data_submitted(). Default values are set by setDefault normally called from within definition() function or by set_data which is called to load database contents into the form.