Early Bird Registration for DrupalCon Portland 2024 is open! Register by 23:59 PST on 31 March 2024, to get $100 off your ticket.
By gajillion on
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
Guess I should have looked at the code.
This kinda sucks. Guess I'm re-writing core code to support nested file names...
In case anyone cares
Very simple edit to handle single-level nesting. In /includes/forms.inc