Not able to make submit button work in form theme in drupal 7

781 Views Asked by At

I am trying to develop a module where in my form needs to be rendered in a tabular form. Everything is working fine except the submit button. It is neither calling default _validation or _submit functions nor _form_alter functions. I don't know where I am missing.

Here is the code for my .module file

<?php 
function mytheme_menu(){
  $items = array();
  $items['enqform']=array(
    'title' => 'Enquiry Form',
    'page callback' => 'mytheme_function',
    'access arguments'=>array('access content'),
    'access callback' => TRUE,
    'type' => MENU_NORMAL_ITEM,
  );

  return $items;
}

function mytheme_function(){
  return theme('enquiry')
}

function mytheme_theme() {
  return array(
    'enquiry' => array(
        'render element' => 'form',
        'template' => 'custompage',
    ),
  );
}

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

  $form['elname'] = array(
    '#type' => 'textfield',
    '#title' => 'Last Name',
    '#size' => 28,
    '#maxlength' => 10,
    '#required' => TRUE, //make this field required
  );

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

  return $form;
}

function enquiry_form_validate($form, &$form_state){
}

function enquiry_form_submit($form, &$form_state) {
  db_insert('form_example')->fields(array(
    'efname'=>$form_state['values']['efname'],
    'elname'=>$form_state['values']['elname'],
    'active' => 1,
    )
  )->execute();
}

and my .tpl.php page looks like this

<?php$form = drupal_get_form('enquiry_form');?>
<h2>Please enter details here</h2>
<?php print render(drupal_render($form['efname']));?>
<?php print render(drupal_render($form['submit']));?>
<?php print render(drupal_render_children($form));?>

When I use 'drupal_get_form' as page callback in my hook menu, submit is working fine, but the purpose of template is of no use. It would be a day saver if someone can guide me where and what am I missing in this code.

1

There are 1 best solutions below

0
On

I think that you should not render the drupal_render_children, you should just print drupal_render_children by itself.

<?php print drupal_render_children($form); ?>