How to place title/label in other cell of the html table

I have:

function hook_theme() {
  return array(
    'hook_form_table' => array(
      // The renderable element is the form.
      'render element' => 'form',

function hook_form_table_form($form = array(), &$form_state) {

    $form['#theme']= 'hook_form_table';
    $form['carmodel'] = array('#type' => 'select',
        '#options' => $options_second,
        '#default_value' => $selected_two,
        '#required' => TRUE, '#title' => t('Car model:'),
        '#validated' => true, 
        '#prefix' => '<div id="replace_carmodel_div">', 
        '#suffix' => '</div>', 

    $options_euro=array("Euro 3,4","Euro 5" );

    $form['euro'] = array('#type' => 'select',
        '#options' => $options_euro,
        '#default_value' => $selected_two,
        '#required' => TRUE, 
         '#title' => t('Euro type:'),
        '#validated' => true, 

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

  return $form;

function theme_hook_form_table(&$variables) {
    $form = $variables['form'];
    $content = '<h2>' . t('Please enter your information below') . '</h2>';

    $content .= drupal_render($form['carmodel']);
     $content.="hire want euro type  with * and label and all";

    $content .= drupal_render($form['euro']);
  return $content;

This give me a table but labels is on top: enter image description here How to render label to put it like this: enter image description here

1 Answer 1


My not nice solution is

function drupal_render_label($field){
    $result= "<div class=\"form-item form-type-".$field['#type']." form-item-".$field['#name']."\">";
    $result.= "<label for=\"edit-".$field['#name']."\">".$field['#title'];
    if ($field['#required']==true){
       $result.= "<span class=\"form-required\" title=\"This field is required.\">*</span>";
    return $result;

and then:


Anyone have sth better?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.