Issue Details (XML | Word | Printable)

Key: MDL-11560
Type: Bug Bug
Status: Open Open
Priority: Major Major
Assignee: Jamie Pratt
Reporter: Mawuli Kuivi
Votes: 0
Watchers: 1
Operations

Add/Edit UI Mockup to this issue
If you were logged in you would be able to see more operations.
Moodle

addGroup method does not add element type

Created: 03/Oct/07 03:10 AM   Updated: 19/Feb/08 10:44 PM
Return to search
Component/s: Forms Library
Affects Version/s: 1.9
Fix Version/s: None

Participants: Jamie Pratt, Mawuli Kuivi and Petr Skoda
Security Level: None
Affected Branches: MOODLE_19_STABLE


 Description  « Hide
I see that when you add an element using the addElement, you get <div class="felement f{ELEMENT_NAME}

When you use addGroup, you set <fieldset class="felement fgroup"><input type.....

I think the groups do like <fieldset class="felement fgroup"> { <div class="felement f{ELEMENT_NAME}} </fieldset>

That is, each element being added by a addGroup should also have its flemtn defined inside the fieldset of the group.

This creates a bug. For example if you create a group of "file" element and something and you try to submit, the file element is not defined hence you cannot submit the file.

 All   Comments   Change History   Version Control      Sort Order: Ascending order - Click to sort in descending order
Jamie Pratt added a comment - 03/Oct/07 12:49 PM
I don't really understand the problem. Can you explain in more detail and / or include a code sample of code that would produce an error.

Mawuli Kuivi added a comment - 04/Oct/07 02:57 AM
In my form, l have

class mod_mymodule_compose_form extends moodleform {
....
...

$mform->addElement('file', 'attachment', "File Attachment");
$mform->addElement('submit','attachfile', "Attach File");
...
--------------------------------

The code above works file. But if l change this to group the items so that they will be on the same line as below, l get error when file is submitted:


class mod_mymodule_compose_form extends moodleform {
....
...

$marray=array();
$marray[] = &$mform->createElement('file', 'fileattachment', get_string('attachment', "internalmail"));
$marray[] = &$mform->createElement('submit', 'attachfile', "Attach File");
$mform->addGroup($marray, 'attachment', "File Attachment", '', false);
...
-------
The second code does not work. When you click on the "Attach File" submit button, l get an error 'Incorrect upload attempt'. I checked it is it coming from

lib/formslib.php
function _validate_files(&$files) {

If you see my comment above, $mform->getElementType($elname) call in the above function is using an array defined in the forms Object called _elementIndex and this array does not have the index the items that have been added using the addGroup method. Hence it is failing.


Mawuli Kuivi added a comment - 04/Oct/07 03:02 AM
I posted this yesterday on the wrong place: http://tracker.moodle.org/browse/MDL-11537#action_35666
---------------
In doing more research on this, l found that the forms element has an array called [_elementIndex] => Array

This array has the location of the items in the array.

The getElementType function in QuickForm.php depends on this.

But when you had items to a group, the items are not part of this index hence getElementType fails.

It would be nice if getElementType can recurse or somehow find item types in a Groups. Or just add the items in the Groups to this index array.


Jamie Pratt added a comment - 04/Oct/07 12:22 PM
I think the problem you are seeing here Mawuli is just related to file upload. To summarise : file upload is failing when the file element is in a group, this is because getElementType is called with the element name and getElementType is not working to get the type of an element within a group. I added Petr as a watcher for this bug as he is the expert on the file upload code.

Mawuli Kuivi added a comment - 05/Oct/07 12:41 AM
You are correct about the getElementType function. It needs to be fix to handle file upload within a group.

Let me know when this is fixed and hope it is fixed before 1.9 is released. Thanks for looking at it in the first place.


Mawuli Kuivi added a comment - 17/Oct/07 03:42 AM
Any news on this topic?

Petr Skoda added a comment - 19/Feb/08 10:44 PM
lowering priority -this does not break current code, though I agree this should be fixed in future