1

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';
    $selected_two="";
    $options_second=array("a");
    $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.="<table>";
    $content.="<tr>";
    $content.="<td>";
    $content.=$form['carmodel']['#title'];
    $form['carmodel']["#type"]="";

    $content.="</td>";
    $content.="<td>";
    $form['carmodel']['#title']="";
    $form['carmodel']['#required']="";
    $content .= drupal_render($form['carmodel']);
    $content.="</td>";
    $content.="<td>";
     $content.="hire want euro type  with * and label and all";
    $content.="</td>";
    $content.="<td>";

    $content .= drupal_render($form['euro']);
    $content.="</td>";
    $content.="</tr>";
    $content.="</table>";
  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

0

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>";
    }
    $result.="</label>";
    $result.="</div>";
    return $result;
}

and then:

  $content.="<td>";
  $content.=drupal_render_label($form['carmodel']);
  $content.="</td>";

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.