-
Bug
-
Resolution: Unresolved
-
Minor
-
None
-
4.5
-
MOODLE_405_STABLE
I discovered a rather strange bug, and it was quite challenging to identify.
In the context of a MOD-type plugin, when using $mform->addElement("filemanager") in the mod_form.php file, I noticed that when the field is optional, the form submits $draftid=0. In my validator, I check if the value is zero and consider it acceptable.
The problem occurs because Moodle, when processing this situation, looks in the database for all files with itemid=0 for the current user. This results in a query like this:
{{SELECT * }}
{{FROM mdl_files }}
WHERE contextid = 5
AND component = 'user'
AND filearea = 'draft'
AND itemid = 0
If more than one file is associated with itemid=0, the system displays the error:
"You cannot attach more than 1 file here."
This happens because, before line 461 of formslib.php, there is no validation to check if the field rule is truly 'required'. The absence of this check allows the issue to occur.
Additionally, there is no validation for itemid!=0.