I'm trying to organize a number of fields inside of a fieldset and upload fields ('#type' => 'file') don't work. The reason is they get "subclassed" differently in the forms module. Here's my fieldset declaration

 $form['submission'] = array(
    '#type' => 'fieldset',
    '#tree' => TRUE,
  );

Now when I put my uploads like this they work fine

   $form['thumbnail'] = array(
      '#type' => 'file',
      '#title' => t('attach your thumbnail here'),
   );
   $form['design'] = array(
      '#type' => 'file',
      '#title' => t('attach your submission here'),
   );

and the rendered code comes out like this

<div class="form-item">
 <label for="edit-thumbnail">attach your thumbnail here: </label>

 <input type="file" name="files[thumbnail]"  class="form-file" id="edit-thumbnail" size="60" />

</div>
<div class="form-item">
 <label for="edit-design">attach your submission here: </label>
 <input type="file" name="files[design]"  class="form-file" id="edit-design" size="60" />

However, when I subclass them into the fieldset like so

   $form['submission']['thumbnail'] = array(
      '#type' => 'file',
      '#title' => t('attach your thumbnail here'),
   );
   $form['submission']['design'] = array(
      '#type' => 'file',
      '#title' => t('attach your submission here'),
   );

The rendered code gives them all the same name

<div class="form-item">
 <label for="edit-submission-thumbnail">attach your thumbnail here: </label>
 <input type="file" name="files[submission]"  class="form-file" id="edit-submission-thumbnail" size="60" />

</div>
<div class="form-item">
 <label for="edit-submission-design">attach your submission here: </label>
 <input type="file" name="files[submission]"  class="form-file" id="edit-submission-design" size="60" />

and therefore only the last one ever actually gets loaded.

Anyone ever run into this or know how to fix it?

Comments

gajillion’s picture

This kinda sucks. Guess I'm re-writing core code to support nested file names...

      if ($form['#type'] == 'file') {
        // To make it easier to handle $_FILES in file.inc, we place all
        // file fields in the 'files' array. Also, we do not support
        // nested file names.
        $form['#name'] = 'files['. $form['#name'] .']';
      }
gajillion’s picture

Very simple edit to handle single-level nesting. In /includes/forms.inc

diff form.inc form.inc.ORIG
664,667d663
<                       if($form['#parents']){
<                               // We're nested.  Change our name
<                               $form['#name'] =  array_shift($form['#parents']);
<                       }