How to make submit button work in form themes I am trying to create a form which calls an external template file to format the form but ended up into a typical issue. This is what I was doing. I created a hook menu and called a theme, in the theme declared the template, and in template called the form elements and rendered along with html code. Everything is working fine except the submit button. If I render form directly, submit is working, or if I use drupal_get_form in menu page callback, it works (again template is not getting applied). I'm confused what am I doing wrong. I am a newbie so excuse me if this is a repetitive or stupid question.

Here is my code.
My module file named agents.module

&lt;?php
function agents_menu(){
  $items=array();

  $items['myform']=array(
    'title'=&gt;'Form',
    'description'=&gt;'Submit Form into database',
    'page callback'=&gt;'agents_form', 
    'access callback'=&gt;TRUE,
    'access arguments'=&gt;array('access content'),
    'type'=&gt;MENU_CALLBACK,
  );

  return $items;
}

function agents_form(){
  return theme('students');
}

function agents_theme(){
  return array(
    'students' =&gt; array(
        'render element' =&gt; 'form',
        'template' =&gt; 'customTemplate',
    ),
  );
}

function students_form($form, &amp;$form_state){
  $form = array();
  $form['efname'] = array(
    '#type' =&gt; 'textfield',
    '#title' =&gt; 'First Name',
    '#size' =&gt; 28,
    '#maxlength' =&gt; 10,
    '#required' =&gt; TRUE, 
  );

  $form['elname'] = array(
    '#type' =&gt; 'textfield',
    '#title' =&gt; 'Last Name',
    '#size' =&gt; 28,
    '#maxlength' =&gt; 10,
    '#required' =&gt; TRUE,
  );
  $form['submit_btn'] = array(
    '#type'=&gt;'submit',
    '#value'=&gt;'Submit',
    '#submit' =&gt; 'agents_myForm_submit'
  );
  return $form;
}

function students_form_validate($form, &amp;$form_state){
  dpm($form_state['ename']);
}

function students_form_submit(){
  dpm('into submit');
}


and my customTemplate.tpl.php code looks like this

&lt;?php 
  dpm(drupal_get_form('students_form'));
  $form = drupal_get_form('students_form');
?&gt;
&lt;div class="left_div"&gt;
  &lt;?php print render($form['efname']); ?&gt;
  &lt;?php print render($form['elname']); ?&gt;
&lt;/div&gt;
&lt;div class="right_div"&gt;
  &lt;?php print render($form['submit_btn']); ?&gt;
&lt;/div&gt;
&lt;?php
  dpm(render($form['form_build_id']));
  print render($form['form_build_id']);
  print render($form['form_token']);
  print render($form['form_id']);
?&gt;
&lt;?php print drupal_render_children($form);


I am a newbie to drupal, and I was not able to figure out what am I doing wrong. If I directly render the form without rendering submit individually, (i.e. print render($form) ) it works fine. It would be a great savior of the day if someone helps me cross this hurdle.
You don't want to run your drupal_get_form from inside your template, you want to render it from your page callback. You'll instead declare the theme for your form with $form['#theme'] = 'students' in order to use your template.

function agents_form() {
  $form = drupal_get_form('students_form');
  return render($form);
}


function students_form($form, &amp;$form_state){
  $form = array();
  $form['efname'] = array(
    '#type' =&gt; 'textfield',
    '#title' =&gt; 'First Name',
    '#size' =&gt; 28,
    '#maxlength' =&gt; 10,
    '#required' =&gt; TRUE,
  );

  $form['elname'] = array(
    '#type' =&gt; 'textfield',
    '#title' =&gt; 'Last Name',
    '#size' =&gt; 28,
    '#maxlength' =&gt; 10,
    '#required' =&gt; TRUE,
  );
  $form['submit_btn'] = array(
    '#type'=&gt;'submit',
    '#value'=&gt;'Submit',
  );

  $form['#theme'] = 'students';

  return $form;
}


You also had a '#submit' attribute on your submit button element but it would need to be set as an array rather than a string '#submit' =&gt; array('agents_myForm_submit'), However I didn't see that submit function defined so I removed it.

Then your customTemplate.tpl.php can be as simple as:

&lt;div class="left_div"&gt;
  &lt;?php print render($form['efname']); ?&gt;
  &lt;?php print render($form['elname']); ?&gt;
&lt;/div&gt;
&lt;div class="right_div"&gt;
  &lt;?php print render($form['submit_btn']); ?&gt;
&lt;/div&gt;
&lt;?php print drupal_render_children($form); ?&gt;