How to hide row cell when using table in forms? I have a field widget that has multiple values per field and some are values or other form types that do not render any visible data. I want to use the table element to encapsulate these fields into proper structure.

The issue I have is that for each field within the "field"(ie. table row) a table cell is created, even for values, which resutls in empty &lt;td&gt;&lt;/td&gt;. Sure, I can use the colspan on headers but that also requires adding some css styling to hide those empty cells to avoid padding/margin offsets from those empty cells.

So I am wondering if it is possible to somehow tell the row which fields to put together into one cell or maybe render them outside of the table itself. I could use a custom template but I need to use the tabledrag so I don't want to reinvent the wheel.

I also don't want to alter the structure of those fields since it is very important the structure stays the same. although I could probably fiddle with array parents, I'd rather not.

So ss there a simple way I can get rid of those empty cells that hold values and hidden fields?

--
I have found an old Drupal issue when I was going through the Table code https://www.drupal.org/node/1248940
I've just implemented it using a theme preprocessor to alter the tag from &lt;td&gt; to &lt;span&gt; and I've added the hidden and aria-hidden attributes. Hidden by itself works but it isn't supported by &lt; IE10.

So as to prevent the loops on every table I've added a class to the table as well so I'm checking for 'form-table' first.

/* Implements MODULE_preprocess_HOOK */
function mymodule_preprocess_table(&amp;$variables) {
  if ( ! in_array('form-table', $variables['attributes']['class']) )
    return;

  // Iterate the variables looking for form elements that have the type hidden
  foreach ($variables['rows'] as $key =&gt; &amp;$row ) {
    foreach ( $row['cells'] as &amp;$cell ) {
      if ( $cell['content']['#type'] == 'hidden' ) {
        $cell['attributes']['hidden'] = TRUE;
        $cell['attributes']['aria-hidden'] = 'true';
        $cell['tag'] = 'span';
      }
    }
  }
}