Note:

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

Talk:lib/formslib.php Form Definition

From MoodleDocs
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

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)

No default value attribute for editor??

tried the context key but doesn't work.

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:
http://pear.saltybeagle.com/HTML_QuickForm_Renderer_Tableless/stack.php
Konrad Lorinczi - - 18:02, 23 March 2011 (UTC)

Multiple file uploads?

If one has multiple files to be uploaded using the form and all files are to go in different location. It feels like, 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()) {

     ...
   $mform->save_files($destination_directory);
     ...

}


How this can be done? Thanks.

Dependent Dropdown Lists

Does Formslib support adding dependent dropdown lists to a form? This is where the options that are displayed on list2 are dependent on the option that is selected on list1. The how to implement dependent dropdown lists discussion on the Using Moodle forum talks about something similar and offers a "hacky" approach. But that was in 2010. Can this be easily done in Moodle 2.5/2.6?

setType default, source links

In the section documenting setType(), it would be great to have links to the source of not only where these are defined (linking the reference to moodlelib.php), but also where they get applied, that is, where the cleaning happens. When I look at this section, I would expect to find information on what the default type is, if none is set, and details on what cleaning happens, or where to find this in the source. How are invalid values dealt with? There is also a reference to format_text(), which could use a link to source.

How can we put links to source into the documentation?

Also helpful would be a discussion of how to set the type of elements created with repeat_elements(). Some clues to this can be found in lib/formslib.php:1027:repeat_elements().