Moodle

addGroup method does not add element type

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Won't Fix
  • Affects Version/s: 1.9
  • Fix Version/s: None
  • Component/s: Forms Library
  • Labels:
    None
  • Affected Branches:
    MOODLE_19_STABLE

Description

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.

Activity

Hide
Jamie Pratt added a comment -

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.

Show
Jamie Pratt added a comment - 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.
Hide
Mawuli Kuivi added a comment -

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.

Show
Mawuli Kuivi added a comment - 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.
Hide
Mawuli Kuivi added a comment -

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.

Show
Mawuli Kuivi added a comment - 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.
Hide
Jamie Pratt added a comment -

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.

Show
Jamie Pratt added a comment - 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.
Hide
Mawuli Kuivi added a comment -

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.

Show
Mawuli Kuivi added a comment - 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.
Hide
Mawuli Kuivi added a comment -

Any news on this topic?

Show
Mawuli Kuivi added a comment - Any news on this topic?
Hide
Petr Škoda (skodak) added a comment -

lowering priority -this does not break current code, though I agree this should be fixed in future

Show
Petr Škoda (skodak) added a comment - lowering priority -this does not break current code, though I agree this should be fixed in future
Hide
Michael de Raadt added a comment -

Thanks for reporting this issue.

We have detected that this issue has been inactive for over a year has been recorded as affecting versions that are no longer supported.

If you believe that this issue is still relevant to current versions (2.1 and beyond), please comment on the issue. Issues left inactive for a further month will be closed.

Michael d;

lqjjLKA0p6

Show
Michael de Raadt added a comment - Thanks for reporting this issue. We have detected that this issue has been inactive for over a year has been recorded as affecting versions that are no longer supported. If you believe that this issue is still relevant to current versions (2.1 and beyond), please comment on the issue. Issues left inactive for a further month will be closed. Michael d; lqjjLKA0p6
Hide
Michael de Raadt added a comment -

I'm closing this issue as it has become inactive and does not appear to affect a current supported version. If you are encountering this problem or one similar, please launch a new issue.

Show
Michael de Raadt added a comment - I'm closing this issue as it has become inactive and does not appear to affect a current supported version. If you are encountering this problem or one similar, please launch a new issue.

People

Vote (0)
Watch (1)

Dates

  • Created:
    Updated:
    Resolved: