function theme_test_form($form) {
  $output = '';
  $output .= drupal_render($form['name']);
  $output .= '<div id="foo">';
 $output .= drupal_render($form['age']);
  $output .= '<div class="messages">';
  $output .= drupal_render($form['details']);
  $output .= '</div></div>';
  $output .= drupal_render($form);
  return $output;
}
function test_form($form_state) {
  // Access log settings:
  $form['firstname'] = array(
    '#type' => 'textfield',
    '#title' => t('First Name'),
    '#size' => 30,
    '#maxlength' => 64,
    '#description' => t('Enter Name'),
    '#required' => TRUE,
  );
  $form['age'] = array(
    '#type' => 'textfield',
    '#title' => t('Age'),
    '#size' => 30,
    '#maxlength' => 64,
    '#description' => t('Enter the Age'),
    '#required' => TRUE,
  );

 $form['place'] = array(
    '#type' => 'textfield',
    '#title' => t('Place'),
    '#size' => 30,
    '#maxlength' => 64,
    '#description' => t('Enter place'),
    '#required' => TRUE,
  );
  $form['hidden'] = array('#type' => 'value', '#value' => 'is_it_here');
  $form['submit'] = array('#type' => 'submit', '#value' => t('Save'));
  return $form;
}

function test_page() {
  return drupal_get_form('test_form');
}

function test_form_validate($form, &$form_state) {
  /*if ($form_state['values']['firstname'] == '') {
    form_set_error('', t('You must enter your name.'));
  }
  if ($form_state['values']['age'] == '') {
    form_set_error('', t('You must enter your age.'));
  }*/
}
function test_form_submit($form, &$form_state) {
  db_query("INSERT INTO {new_form} (name, age) VALUES ('%s', %d)", $form_state['values']['name'], $form_state['values']['age']);
  drupal_set_message(t('Your form has been saved.'));
}
print test_page();

i used the code from the http://api.drupal.org/api/drupal/developer--topics--forms_api.html/6 and the form gets displayed and everythings working fine .but the theme_test_form is not working even if i have added the corresponding css in theme.css file. IS there any additional work to be done for css to get applied or theme change to get applied..

Thanks,
Pradeep

Comments

gbernier’s picture

Hey Pradeep,

You need to add $form['#theme'] = 'test_form'; This tells the functions that process the form to call theme_test_form

Cheers,
Gene

Gene Bernier
gene@cheekymonkeymedia.ca
COO, Top Monkey Wrencher
Cheeky Monkey Media
http://cheekymonkeymedia.ca

arunms’s picture

Hi Pradeep/Gene:
I added the #theme attribute to the form, but still couldn't get the form to call the theme function. Is there any additional step involved in calling the custom theme function.

Thanks.
Arun M

jaypan’s picture

Have you registered the theme function in hook_theme()?

Contact me to contract me for D7 -> D10/11 migrations.

arunms’s picture

I just registered the theme and it works like a charm.

ivankin’s picture

How should I do that?

Have the same problem.

prakashp’s picture

Implement hook_theme() in your module.


function yourmodule_theme() {
  return array(
    'test_form' => array(
      'arguments' => array('form' => NULL),
    ),
  );
}

Clear the cache after implementing this.