[support] HowTo: table within a fieldset

Jason Flatt drupal at oadae.net
Wed Oct 25 22:04:31 UTC 2006


On Wednesday 25 October 2006 14:01, Stefan Borchert wrote:
> Hi.
> After posting by accident to the themes-list, I try it here:
>
> For a module settings page I would like to build up a table of
> available extensions (don't care about, just think of a simple table)
> but this table should be within a fieldset (collapsible).
[ s n i p ]
> Other form elements above and below of this fieldset (for
> example the submit button) are displayed correctly but I can't put the
> table into the fieldset. How do I handle this?
> I can build the table and can build the fieldset but the table doesn't
> want to appear within the fieldset.
>
> Any ideas (or a handbook page) or is this simply impossible?


I'm assuming I know what you're talking about, so if I fail to answer your 
question, please try again and rephrase it.  (Or wait for someone with a clue 
to answer.)

You could try using both the markup type and the #prefix & #suffix properties 
to accomplish this.

Something like this untested, modified snippet you posted:

  $form['ext'] = array('#type' => 'fieldset',
      '#collapsible' => true,
      '#collapsed' => true,
      '#tree' => true,
      '#title' => t('Extensions'));

  // build extension table
  foreach ($extensions as $key => $extension) {
    $form['ext'][$key]['status'] = array('#type' => 'checkbox',
      '#default_value' => $extension['status'],
      '#prefix' => '<tr><td>',
      '#suffix' => '</td>');
    $form['ext'][$key]['weight'] = array('#type' => 'weight',
      '#default_value' => $extension['weight'],
      '#prefix' => '<td>',
      '#suffix' => '</td>');
    $form['ext'][$key]['title'] = array('#value' => $extension['title'],
      '#prefix' => '<td>',
      '#suffix' => '</td></tr>');
  }

You'll have to play around with the markup type to get your table tags in 
there the way you want them.

Here's the reference chart for more information:
http://api.drupal.org/api/4.7/file/developer/topics/forms_api_reference.html

-- 
Jason Flatt
http://www.oadae.net/
Father of Six:  http://www.flattfamily.com/ (Joseph, 13; Cramer, 11; Travis, 
9; Angela; Harry, 5; and William, 12:04 am, 12-29-2005)
Linux User:     http://www.sourcemage.org/
Drupal Fanatic: http://drupal.org/


More information about the support mailing list