Talk:lib/formslib.php Form Definition

Revision as of 08:45, 12 July 2011 by Shardul Toro (talk | contribs) (Multiple file uploads: new section)

Jump to: navigation, search

There's items on here (e.g. 'duration') that are 2.0 only. Please can people adding them mark them as such to avoid confusion. Ta --Howard Miller 11:42, 23 July 2009 (UTC)

Hi Howard, You can just add {{Moodle 2.0}} to those items. I did that for 'duration'. --Frank Ralf 11:54, 23 July 2009 (UTC)

Use Static elements with care?

Why are static elements listed as being used with care?

Please do not create conditional elements in definition(), the definition() should not directly depend on the submitted data.

I'm really not sure what this means. Does it actually mean "do not create elements that are conditional upon the values of other submitted elements" as opposed to not creating conditional elements at all? Lots of forms have conditional elements --Howard Miller 13:06, 6 February 2011 (UTC)

Yes, it means don't create things that are conditional on the data that the form will be editing. It is OK to condition on admin settings (e.g. if conditional activities are turned off, those options do not appear on the mod_edit forms. Or, perhaps, on capabilities. However, in that case you have to be careful. If someone without the capability uses the form, you have to make sure that when they submit, you don't overwrite the correct value in the database with blank from the form. In that situation, it may be better to use hardFreeze on those form elements, instead of conditionally omitting them.--Tim Hunt 15:14, 6 February 2011 (UTC)

Very disappointing, that nested fieldsets are not supported :(

"$mform->addElement('header', 'nameforyourheaderelement', get_string('titleforlegened', 'modulename')); You can't yet nest these visible fieldsets unfortunately. But in fact groups of elements are wrapped in invisible fieldsets. You close a fieldset with moodle_form's closeHeaderBefore method. You tell closeHeaderBefore the element before you wish to end the fieldset. A fieldset is automatically closed if you open a new one."

Should be possible to nest fieldsets! Please add this feature!

As I know this feature was already added to QuickForms.
See example QuickForm solution of nested fieldset here:
Konrad Lorinczi - - 18:02, 23 March 2011 (UTC)

Multiple file uploads

If I have multiple files to be uploaded using the form and all files are to go in different location. The below code does not satisfy the needs to do anything of this sort.

after form submission and validation use

if ($data = $mform->get_data()) {



How I can go about that? Thanks.