I've got a theme function in a module that I'm working on. It's for a configuration page with several different sets of controls that are grouped into fieldsets. One group of items consists of tabular data. I'd like this group to be placed in a fieldset, but I can't find a way to do so. There doesn't seem to be a way to specify how a table should be placed in a fieldset.
Are there any examples of how to do this? Has anyone run into this problem and figured it out? It was mentioned here, but there was never any resolution.
Right now I've got this bit of code for the form:
<code>// Create the Link Types section.
$form['relatedlinks_types'] = array(
'#tree' => TRUE,
'#weight' => 3,
);
And this for the rendering:
<code>// Render the link type data in a table sorted by weight.
foreach (array_keys($weights) as $type) {
$rows[] = array(
form_render($form['relatedlinks_types'][$type]['name']),
form_render($form['relatedlinks_types'][$type]['enabled']),
form_render($form['relatedlinks_types'][$type]['weight']),
form_render($form['relatedlinks_types'][$type]['title']),
form_render($form['relatedlinks_types'][$type]['max']),
);
}
$header = array(t('Link Type'), t('Enabled'), t('Weight'), t('Title'), t('Limit'));
$output = theme('table', $header, $rows, array('style' => 'width: 100%'));
When I add a '#type' => 'fieldset', to the form element $form['relatedlinks_types'], the table is rendered outside of the fieldset even if I replace all of the form_render() calls with form_render($form['relatedlinks_types'][$type]). Placing the fieldset $form['relatedlinks_types'] inside of the call puts the entire fieldset inside one cell (which isn't too useful).
Anyone have any ideas?
Comments
To achieve this you need to
To achieve this you need to create a special theme function for the fieldset. In your theme function for the form, add a '#theme' value to the fieldset data. Set this to call a seperate theme function to theme the inside of the fieldset.
Fantastic
Thanks! That worked wonders. The only additional thing I had to do was change the theme function line
$output = theme('table', $header, $rows, array('style' => 'width: 100%'));to:
$output = theme('table', $header, $rows, array('style' => 'width: 100%', 'class' => 'form-item'));I'm having a really bad
I'm having a really bad blonde moment here, and I have no idea how to implement what you suggest here :-)
Having the same issue that the original poster did - I have a themed form, but the fieldset 'box' doesn't appear around the table and form. Instead, it shows up just below it.
Whenever I try to add a '#theme' value, the value of the elements usually changes to '#theme'.. set the value of the fieldset form element, and the '#theme' text shows up in the fieldset outline.
I'm sure this is painfully simple... but I'm just not seeing it right now.
Any help is appreciated!
Example
I'm not really sure what the problem is in your situation, but have a look at how I did this in relatedlinks.module. The two relevant functions are _relatedlinks_settings_form() and theme_relatedlinks_types_table().
Got the issue resolved in
Got the issue resolved in http://drupal.org/node/98065.
Thanks though!!
An other solution:
Thanks, this helped me a lot
Thanks, this helped me a lot today, this is a quick way that works perfectly.
You HAVE to assume your visitor is a maniac serial killer, out to destroy your application. And you have to prevent it.
Updated link
Thanks colan, looking at your implementation helped. Since Drupal is now on Git, here's the new link to the module source:
http://drupalcode.org/project/relatedlinks.git/blob_plain/refs/heads/mas...
THAAANNKSSS A BUNCH
your last solution worked perfectly for me; i knew it was a possible but since im such a newb i dont know what the form type to actually call up the table in a field set which was 'mark up' still dont know what it means in forms; but i'll defo have a look into it!
AGAIN many thanksss!!!!!!