Hello

I'm trying to render a table inside a form 'fieldset'.

I have a form generated like this:

$res = db_query("SELECT  .... ");
if (db_num_rows($res))
{
    $dkppform['dkpp'] = array(
        '#type' => 'fieldset',
        '#title' => t('Attendance'),
        '#tree' => true,
    );
    
    while ($r = db_fetch_object($res))
    {
        $dkppform['dkpp'][$r->MemberName]['pts'] = array(
            '#type' => 'textfield',
            '#size' => 2,
        );
        $dkppform['dkpp'][$r->MemberName]['start'] = array(
            '#type' => 'hidden',
            '#value' => $r->StartTime,
        );
        $dkppform['dkpp'][$r->MemberName]['end'] = array(
            '#type' => 'hidden',
            '#value' => $r->EndTime,
        );
        
    }
    $output .= drupal_get_form('dkp_assign_dkpp', $dkppform);
}

Without any theme function, the fields display all in a line, within the outline of the 'Attendance' fieldset.

I created a theme function for the form that reads:

function theme_dkp_assign_dkpp($form)
{
    $header = array(
        t('Name'),
        t('Start'),
        t('End'),
        t('Total'),
        t('PTS +'),
    );
    foreach(element_children($form['dkpp']) as $value)
    {
        $rows[] = array(
            $value,
            $form['dkpp'][$value]['start']['#value'],
            $form['dkpp'][$value]['end']['#value'],
            format_interval($form['dkpp'][$value]['end']['#value'] - $form['dkpp'][$value]['start']['#value']),
            form_render($form['dkpp'][$value]['pts']),
        );
    }
    $output = theme('table', $header, $rows);
    
    $output .= form_render($form);
    return $output;        
}    

This creates a table with form elements in the 4th table column (as I want). However, the fieldset outline now appears below the table I created.

If I create a submit button, but don't theme it, it appears inside the fieldset.

Any help or direction would be greatly appreciated!

Comments

sime’s picture

<?php
// Try replacing this:
// $output = theme('table', $header, $rows);
// with:
$form['dkpp']['#children'] = theme('table', $header, $rows);
?>
timatlee’s picture

Bah, so simple.

Thank you so much. I kept messing around with #theme and #children but in all the wrong places.

sime’s picture

Ah, I know the feeling. I beat myself around the head with Fapi frequently.