Forms in a table won't show I am trying to display a form in a table, but it is showing an empty result, while the header is displayed. I can't understand what I am doing wrong.

/*
 * cart form and page display
 */
function cart_page_form() {
  $form=array();
  $form['#tree'] = TRUE;

  $checkboxes=array();

  foreach($_SESSION['cart'] as $key =&gt; $qty) {
    $checkboxes[$key] = '';

    $form['checkboxes'][$key] = array(
      '#type' =&gt; 'checkbox',
      '#default_value' =&gt;check_plain($key),
    );

    $form['quantinty'][$key] = array(   
      '#type' =&gt; 'textfield',
      '#size' =&gt; 4,
      '#maxlength' =&gt; 4,
      '#id' =&gt; 'prod_qty',
      '#default_value' =&gt; check_plain($qty),
    );

    $form['price'][$key]['#value'] = t('244p');
  }

  $form['remove'] = array(
      '#type'           =&gt; 'button',
      '#name'           =&gt; 'remove_selected',
      '#value'          =&gt; t('Remove selected'),
  );

  $form['submit'] = array(
    '#type'           =&gt; 'button',
    '#name'           =&gt; 'update_quantity',
    '#value'          =&gt; t('Update'),
  );

  $form['checkout'] = array(
    '#type'           =&gt; 'submit',
    '#name'           =&gt; 'checkout',
    '#value'          =&gt; t('Зделать заказы'),
  );

   return $form;
}

/**
 *Implementation of hook_theme().
 *
 */
function yalublurudn_theme() {
  return array(
    'cart_page_form' =&gt; array('variables' =&gt; array('form' =&gt; NULL)),
  );
}



/**
 * display cart page
 */
function theme_cart_page_form($form) {
  $rows = array();

  foreach(element_children($form) as $key) {
    if (isset($form['checkboxes'][$key])) { //// make sure this is one of our table rows
      $row = array();
      $row[] = array('data' =&gt; drupal_render($form['checkboxes'][$key])); 
      $row[] = array('data' =&gt;drupal_render($form['quantinty'][$key]));
      $row[] = array('data' =&gt;drupal_render($form['price'][$key]));
      $rows[] = $row;
    }
  }

  $header = array(
    'Checkboxes',
    'Title',
    'Quantity',
  );

  $output = theme('table', array('header' =&gt; $header, 'rows' =&gt; $rows));
  $output .= drupal_render($form); // Render rest of form components.

  return $output;
}
In Drupal 7, a theme function like yours receives an array containing the variables declared in hook_theme(). If you execute element_children($form) with the form you defined, you get an array containing the following values:


checkboxes
quantinty
price
remove
submit
checkout


The control statement if (isset($form['checkboxes'][$key])) { will not be executed, if not in the case you have $form['checkboxes']['checkboxes'], etc.

Your theme function should use the following code.

function theme_cart_page_form($variables) {
  $form = $variables['form'];
  $rows = array();

  foreach(element_children($form['checkboxes']) as $key) {
    $row = array();
    $row[] = array('data' =&gt; drupal_render($form['checkboxes'][$key])); 
    $row[] = array('data' =&gt;drupal_render($form['quantinty'][$key]));
    $row[] = array('data' =&gt;drupal_render($form['price'][$key]));
    $rows[] = $row;
  }

  $header = array(
    'Checkboxes',
    'Title',
    'Quantity',
  );

  $output = theme('table', array('header' =&gt; $header, 'rows' =&gt; $rows));
  $output .= drupal_render_children($form); // Render rest of form components.

  return $output;
}


Actually, you should declare the theme function using the following code.

function yalublurudn_theme() {
  return array(
    'cart_page_form' =&gt; array('render element' =&gt; 'form'),
  );
}