Form in custom template does not submit data I have a custom form which I render in a custom template. I render the elements separately but the submit button does not fire the data to the validation/submit function. When I render the whole form at once it works fine.

This does not work:

$form = drupal_get_form('my_module_form');
print render($form['title'];
print render($form['submit'];
print drupal_render_children($form);


This works:

$form = drupal_get_form('my_module_form');
print render($form);


This also works:

$form = drupal_get_form('my_module_form');
print render($form['title']);
print render($form);


So apparently I'm missing something but can't find what. Can somebody give me a hint what I'm doing wrong?
Check the html your template outputs - I am pretty sure it is missing the &lt;form&gt; tag around your fields - without that element your form wont submit however as it contains necessary data (post methode and action to name two).

drupal_get_form() retrieves the entire render array for a functional form, but you only pick two form elements to print to screen. It does display the elements because they are themselves valid render arrays, but the functionality of the form is lost that way.

If you really want to ommit fields in the template try to unset the fields you do not want to display. E.g. unset($form['field_to_hide']). This leave the render array of the form intact.



That said, hidding fields is commonly done in a preprocess function and not in the template itself. Since it is a custom form you can do it directly in your form declaration. 

$form['field_to_hide']['#access'] = 0;
$form['field_to_hide']['und']['#disabled'] = TRUE;


You can use this approach to set custom data you want to save with the form and the user isn't supposed to see. It's basically a hidden field.



If you just want to seperate the fields to add additional wrapper elements or classes you can do that in the form as well:

$form['your_field'] = array(
  //[...] 
  '#prefix' =&gt; '&lt;div class="some-wrapper-class"&gt;',
  '#suffix' =&gt; '&lt;/div&gt;',
  '#attributes ' =&gt; array('class' =&gt; array('element-class'));
);


Check the Form API page to see for which element the two options are available for: FAPI