How can I permanently expand the "File attachment" fieldset?
jeeves - February 27, 2008 - 06:05
By default, the "File attachments" fieldset loads up collapsed when editing or creating a node. This creates a problem for site users because they don't notice where they are supposed to upload files.
Is there anyway I can just have the File attachment fieldset just load up expanded, so it's easy to spot?

Override theme_fieldset
It's not trivial, but the most straightforward way would be to include in your theme an override of the theme_fieldset function
http://api.drupal.org/api/function/theme_fieldset
But I might be over-thinking this one.
[You could also add a touch of jQuery to the page, so that the fieldset opens at load.]
Something like (this is UNTESTED)
<?php
function YOUR_THEME_NAME_fieldset($element) {
if ($element['#collapsible']) {
drupal_add_js('misc/collapse.js');
if (!isset($element['#attributes']['class'])) {
$element['#attributes']['class'] = '';
}
$element['#attributes']['class'] .= ' collapsible';
if ($element['#collapsed'] && $element['#title']!='File attachments') {
$element['#attributes']['class'] .= ' collapsed';
}
}
return '<fieldset' . drupal_attributes($element['#attributes']) .'>' . ($element['#title'] ? '<legend>'. $element['#title'] .'</legend>' : '') . ($element['#description'] ? '<div class="description">'. $element['#description'] .'</div>' : '') . $element['#children'] . $element['#value'] . "</fieldset>\n";
}
?>
Looks good
quick follow up. I just tested this on a (local) drupal test site. Seems to work.
Anyone else, feel free to chime in if there's an even easier solution.
What about
What about this:
$form['attachments']['#collapsed'] = false;Where are you placing that
Where are you placing that line of code?
In any hook_form_alter
In any hook_form_alter implementation at your modules, you could alter whatever form you want (i.e. [nodetype]_node_form). You'll be altering the behaviuor of attachment fieldset to be always expanded (in other words never collapsed) by this code snippet:-
function [module-name]_form_alter($form_id, &$form) {if($form_id == [node-type]_node_form') {
$form['attachments']['#collapsed'] = false;
}
}
I hope that helps
True
Yeah, this looks good to me. I was assuming that Jeeves wanted every node form to always behave this way and thus wanted to do this on the theme level, rather than build a module just to do that. But re-reading his first post, that's not entirely clear.
Jeeves? Any update on this?
looks but but doesn't work for me
hi!
Seems to be a nice improvement indeed. I applied it on a Drupal 6 site i am building, but doesn't seem to work. It is supposed to have effect at node creation time in that form as well, isn't it? Here's the code that doesn't work for me, it's in a module file which is enabled on the site, and there are no other custom modules altering forms:
<?phpfunction lsesu_form_alter($form_id, &$form)
{
if($form_id == 'gallery_node_form')
{
$form['attachments']['#collapsed'] = false;
// Tried with and without this but no effect:
return drupal_render($form);
}
}
?>
Better in template.php
You can force it in template.php for each theme with this code if you know the form_id
function phptemplate_[FORM_ID]_form($form){
$form['attachments']['#collapsible'] = false;
return drupal_render($form);
}
Good luck ;-)
----------------------
Freelance
http://programadorphp.es
jQuery code works perfectly!
Just copied and pasted your code in my theme's template file, changed the theme name to my own, and VOILA! It works like a charm. Just wanted to send a quick thanks.
Hillary
Add this to your
Add this to your template.php, it will open the file attachments fieldset on all node forms:
<?php
// Open the file attachments collapsible block in a full state
function phptemplate_node_form($form) {
$form['attachments']['#collapsed'] = FALSE;
return drupal_render($form);
}
?>
Not working for me! Help!
I am trying to do exactly what you described. I have used the code provided by aschiwi and many different variations of the code provided by vigoncas. However it's not working for me.
I have Drupal 6.13 and am using garland. I have pasted the code in template.php in themes/garland. I have tried function names with prefix phptemplate (similar to the other functions that are in template.php for garland) and prefix garland. My cache is cleared and turned off. Can anyone who has gotten this to work post more details? Or does anyone know what I might be missing?
Thanks!
Some additional information: the form_id is 'contributed_node_form'; I have tried function names in any combination of
garland_ or phptemplate_
plus
node_form
contributed_node_form
contributed
If there is a syntax error in the template.php file I get a warning, so I believe I am editing the right file. However, I don't think it loads that specific function at all (I tried "return drupal_render ($form['attachments']); " just to see if it would truncate the form and nothing happened).
A solution
I have installed the itweak module (http://drupal.org/project/itweak_upload) which does what I needed.
Interestingly after that the phptemplate_node_form ($node) function in template.php started to work! I needed it to collapse the upload path section and now it works. There must have been a conflict with some module I have.
FYI, here is my code for collapsing the upload path section (I have path auto so it's not necessary to display it):
function phptemplate_node_form($form) {$form['path']['#collapsed'] = true;
return drupal_render($form);
}
Don't understand - Want File Attach Fieldset Expanded by Default
Folks,
Sorry for the lack of understanding here. I've tried the snippets of code here in my drupal install and it doesn't work. There is either no action or I get a white screen.
Can someone help out with some details on how I accomplish this. Here is my config:
Drupal 6.14
Access to update.php Protected
CAPTCHA Already 6 blocked form submissions
Configuration file Protected
Cron maintenance tasks Last run 8 min 52 sec ago
You can run cron manually.
Database updates Up to date
File system Writable (public download method)
GD library bundled (2.0.34 compatible)
Image import Import directory /var/www/html/tmp exists.
Image module directories Exists (sites/default/files/images).
Image toolkit The gd toolkit is installed.
MySQL database 5.0.84
MySQL database for event module 5.0.84
PHP 5.2.9
PHP memory limit 64M
PHP register globals Disabled
Unicode library PHP Mbstring Extension
Web server Apache/2.2.11 (Fedora)
I recommend you try out
I recommend you try out iTweak Upload module. All you do is install it and it will immediately give you a prettier upload form which is also NOT collapsed. So give it a try if coding is giving you a hard time.