The object: to use the forms API to render tabular data
This can probably be done by extending the form builder functions and inserting table structure where currently we have fieldset structure.
Table layouts are not all bad. Sometimes, when dealing with actual data, a table is the right thing. Could phpadmin work without tables? Anyway, my data structure needs tables. And form elements inside them.
".htmlspecialchars($table)."
form:
fieldset:
field: 'Dewey'
fieldset:
field: 'Huey'
field: 'Louie'
And once that's taking shape, I need to fill in the Forms API verbose definitions.
".print_r($form,1).""; // save a copy before processing $form2 = $form; $got_form = drupal_get_form('form_id', $form); //print('form is initialized'); //print("
got form: ".htmlspecialchars(print_r($form,1)).""); $output .= "
This form definition now gets run through the wringer,
and after drupal_get_form() is done with it, it renders like:
Formgroups from my trivial example become trs, fields become tds.
This is simply convenient, in practice the actual nesting may have to
be thought out... but it's no harder than the old theme_form() function.
I define a few new rendering functions
theme_tr(), theme_td()
for the formbuilder to find.
Publish these with a hook_elements() implimentation to declare their existance and how I expect them to behave.
Add some logic to allow lazy definitions ( any child of a TABLE is expected to be a TR, any child of a TR must be a TD ) ... using a '#process' parameter. This process is a shortcut, but it assumes that anonymous arrays should implicitly have an appropriate '#type' set, and that elements that don't fit the rules of table structure will be shuffled down until they find a td to fall into.
I'll modify the form structure I began with to get:
table:
tr:
td:
field: 'Dewey'
tr:
td:
field: 'Huey'
td:
field: 'Louie'
";
$form2['group']['#type'] = 'formtable';
$form2['group']['#attributes'] = array('border'=>'2');
// turn formgroups into trs,
// the items within them will get wrapped in tds
$form2['group']['row1']['#type'] = 'tr';
$form2['group']['row2']['#type'] = 'tr';
$output .= "It now looks like:".htmlspecialchars(print_r($form2,1)).""; $output .= "
".htmlspecialchars(print_r($form2,1)).""; $output .= " Setting
drupal_get_form() on this new structure now gives me:
".htmlspecialchars(print_r($got_form,1))."
And with some work, the rest of the forms arsenal can be squeezed into this page-building! Dunno how far I can drag this towards the table-builder with sorting columns and all. I don't think I need that yet..
Note how the button element (that was simply defined as a top-level member of the form) has ended up in its own cell. This could be constructed neater if you took the time, but I'm letting default behaviour format it for now.
I have some tweaking to do to enforce XHTML compliance (TBODY, maybe TH and that crap) but it looks trivial. TD attributes like colspan can be added in the same way as the old theme_table() did and the new forms API does.
"; return $output; } /** * Build an HTML tag. * Very generic. * Uses #type, #attributes, #children and #value */ function theme_element($element){ return '<'.$element['#type'] . drupal_attributes($element['#attributes']) .' >' . $element['#children'] . $element['#value'] . ''.$element['#type'].">\n"; } function theme_formtable($element){ return '