This tutorial is for Drupal 6. The Drupal 7 tutorial is here: Themeing Drupal 7 forms into tables with checkboxes or radios.
Turning forms into a table of information, such as can be seen on the users administration page (
admin/user/user) or the content administration page (
admin/content/node) is not the easiest process in Drupal 6. Even looking at the code that is used to create these pages, it can be hard to see what exactly is going on. So lets take a look at how to do this.
First, let's look at our final goal. Drupal comes bundled with a nice little function for creating tables, theme_table(). This function requires two arguments:
$header, an array containing the header cell elements of the table, and
$rows, and array containing all the data (cells) of the table.
$rows is actually a multi-dimensional array, with the top level being the rows, then and the next level being the cells of the row.
Our goal is to build these arrays. In this tutorial, I will be putting together a nice little table that looks like the following:
| ❏ | First Name | Last Name
| ❏ | Indiana | Jones
| ❏ | Darth | Vader
| ❏ | Super | Man