Trying to create a cell when using tables in forms

tw flag

In one of my custom Drupal modules I'm trying to crate a form that also contains a table. One of the table sections looks like the following:

$form['consumption_' . $week]['mood']['title'] = array(
  '#markup' => $this->t('Mood'),

for ($i = 0; $i <= 6; $i++) {
  $options = array(
    '1' => t('choice 1'),
    '2' => t('choice 2'),
    '3' => t('choice 3'),
    '4' => t('choice 4'),

  $form['consumption_' . $week]['mood']['entry_dropdown_' . $i] = array( 
    '#type' => 'select',
    '#options' => $options,
  $form['consumption_' . $week]['mood']['entry_toggle_' . $i] = array(
    '#type' => 'radios',
    '#options' => array( 
      1 => $this->t('Yes'),
      0 => $this->t('No'),
    '#default_value' => 0,

Everything works fine so far. What I would like to do now is to combine the dropdown and the radio elements so that these elements are in one cell. With the code above, they are in the same row but not in the same cell.

I've tried to work with

'#prefix' => '<td>'


'#suffix' => '</td>'

but I can't seem to get it to work correctly.

Any ideas on how to combine those two elements in one cell will be highly appreciated. Thanks very much!


The code that generates the table looks like the following:

$form['consumption_' . $week] = array(
  '#type' => 'table',
  '#title' => 'XYZ',
  '#header' => array(' ', 'Day 1', 'Day 2', 'Day 3', 'Day 4', 'Day 5', 'Day 6', 'Day 7'),
cn flag
It looks like you've forgotten to post the code which generates the table
unusedspoon avatar
aq flag
Have you seen this example Try with `[$i]` on each item like the example
Quetzcodecoatl avatar
tw flag
Thank you so much for the help guys! The ```[$i]``` did the trick. Works like a charm! THANKS!
I sit in a Tesla and translated this thread with Ai:


Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.