[development] Form fields in a table

Jeff Greenberg jeff at ayendesigns.com
Fri Sep 3 17:18:14 UTC 2010


Arrgh. Ok, I've made all those changes, and here's what it looks like 
(below). What I'm getting is the non-table form stuff, a vertical 
stacking of all the form fields that should be in the table, and then 
the table header, so the fields are being rendered (and the default 
value is showing--hoorah!), but outside of and previous to the table.

form stuff
.
.
             $form['table'] = array(
                 '#theme' => 'my_form_as_table',
             );
             while (loop through recordset)    {
                 $form['table'][$record->id]['field1'] = array (
                     field stuff
                 );
                 $form['table'][$record->id]['field2'] = array (
                     field stuff
                 );
                 .
                 .
                 .
             }
             $form[] = array (
                 '#type' => 'submit',
                 '#value' => 'Save Changes',
             );
         }
function theme_my_form_as_table(&$elements) {
$header = array(t('a'),t('b')...

foreach ($elements['table'] as $k => $f) {
     $rows[] = array($f['field1'],$f['field2'], 
drupal_render($f['field3'])...
                      );
}
return theme('table', $header, $rows) . drupal_render($elements);
}


On 09/03/2010 11:30 AM, John Fiala wrote:
> Well, you can do a fieldset if you like.  But it seems that you don't
> need to have a fieldset to theme a group of fields, you just need to
> group them in the array.  So...
>
>    


More information about the development mailing list