Submit handler doesn't work after theming the form I have a form:

function payment_system_coeff_form($form, &amp;$form_state) {
  list($_SESSION['payment_systems'], $_SESSION['coefficients']) = payment_system_table();

  $form['submit'] = array(
    '#type' =&gt; 'submit',
    '#value' =&gt; t('Submit'),
  );

  return $form;
}

function payment_system_coeff_form_submit($form, &amp;$form_state) {
  var_dump($form_state['input']);
  exit;
}


It works, when I submit it - I get the text printed. 

But when I add the theme for it:

function payment_system_theme($existing, $type, $theme, $path) {
  $path = drupal_get_path('module', 'payment_system');

  return array(
    'payment_system_coeff_form' =&gt; array(
      'render element' =&gt; 'form',
      'path' =&gt; $path,
      'template' =&gt; 'table',
    ),
  );
}


table.tpl.php

&lt;table cellspacing="0" cellpadding="4" border="1"&gt;
  &lt;tr&gt;
    &lt;th&gt;&lt;/th&gt;
    &lt;?php
      foreach ($_SESSION['payment_systems'] as $name) {
        print "&lt;th&gt;$name&lt;/th&gt;";
      }
    ?&gt;
  &lt;/tr&gt;
  &lt;?php
    $i = 0;
    foreach ($_SESSION['payment_systems'] as $index1 =&gt; $name) {
      print '&lt;tr&gt;';
      print "&lt;th&gt;" . $_SESSION['payment_systems'][$index1] . "&lt;/th&gt;";

      $j = 0;
      foreach ($_SESSION['payment_systems'] as $index2 =&gt; $name) {
        if ($j &lt; $i) {
          print '&lt;td&gt;&lt;/td&gt;';
        }
        else if ($j === $i) {
          print '&lt;td&gt;X&lt;/td&gt;';
        }
        else {
          if (isset($_SESSION['coefficients'][$index1][$index2])) {
            $form["coefficients[$index1][$index2]"] = array(
              '#type' =&gt; 'textfield',
              '#required' =&gt; FALSE,
              '#size' =&gt; 10,
              '#attributes' =&gt; array(
                'name' =&gt; "coefficients[$index1][$index2]", 
                'style' =&gt; 'text-align: right;'
              ),
              '#value' =&gt; $_SESSION['coefficients'][$index1][$index2],
             );

            print "&lt;td&gt;" . render($form["coefficients[$index1][$index2]"]) . "&lt;/td&gt;";
          }
          else {
            print "&lt;td&gt;&lt;input type='text' name='coeffitient[$index1][$index2]' value='' /&gt;&lt;/td&gt;";
          }
        }
        ++$j;
      }

      print '&lt;/tr&gt;';
      ++$i;
    }
  ?&gt;
&lt;/table&gt;
&lt;div style="text-align: center;"&gt;&lt;?php print render($form['submit']); ?&gt;&lt;/div&gt;


Output of the form looks like this:



It stops working: I don't get any text when submitting the form. How to fix?
I know you've found an answer to your question, but I just want to explain why did you get that problem.

Drupal adds form_build_id, form_token, form_id (hidden fields) for security reasons and it's some purposes, while you're theming the form with template file and render its fields manually usually miss to include those fields, after that you form submission stops working. Recently this problem happened in my Symfony project (I'd found the solution) and after few days in my Drupal project, the solution was the same;

If you render the fields manually and also call drupal_render_children function, you will find that fields can be duplicated, my solution was rendering those fields also, like this:

print render($form['form_build_id']);
print render($form['form_token']);
print render($form['form_id']);


In my case for some reason drupal_render_children duplicated my form fields (I think this is normal, because I manually rendered the fields plus called drupal_render_children), that's why I ended up with this solution.