Render form with ajax submit I have a custom form in a module, similar to this example:

function mymodule_form($form, &amp;$form_state) {
   $radio_options = array(...);
   $form = array();
   $form["wrapper"] = array("#markup" =&gt; "&lt;div id='test-ajax'&gt;&lt;/div&gt;");
   $form['choice'] = array(
       '#title' =&gt; '',
       '#type' =&gt; 'radios',
       '#options' =&gt; $radio_options,
   );
   $form['submit'] = array(
       '#type' =&gt; 'submit',
       '#value' =&gt; t('Vote'),
       '#ajax' =&gt; array(
           'callback' =&gt; 'demo_form_ajax_submit',
           'wrapper' =&gt; "test-ajax",
           'method' =&gt; 'replace',
           'effect' =&gt; 'fade',
       ),
   ); 
   return $form;
}

function demo_form_ajax_submit($form, $form_state) {
   var_dump("something");
}


And I'm printing that form in template like this:

&lt;div class='row'&gt;
   &lt;?php print render($form['choice']); ?&gt;
   &lt;?php print render($form['form_build_id']); ?&gt;
   &lt;?php print render($form['form_token']); ?&gt;
   &lt;?php print render($form['form_id']); ?&gt;
   &lt;?php print render($form['submit']) ?&gt;
&lt;/div&gt;


The form is printed correctly and even the button shows the ajax icon when clicked, but it does not work. When I check the logs it shows 2 errors:


Notice: Undefined index: form_build_id in ajax_get_form() (line 325 of...
Invalid form POST data.


It is similar to this issue Ajax not working for themed form but it does not work even adding drupal_render_children($form); at the bottom of the template.

Notes:


I added drupal_add_library('system', 'drupal.ajax'); in the module.
I'm using jQuery 1.7
I also tested drupal_render() instead of render().
Instead of print rendering the individual items, you can try to build your form using the drupal_get_form core function, which allows Drupal to add all the extra components to the form (including the Ajax call). 

So in your template it would like like this:

$output = drupal_get_form('mymodule_form');
print drupal_render($output);