1

How do I display a form followed by a table in a module??

I have this:

function main_function(){
  $form = drupal_get_form("report_details_form");
  $tabb = array(
    'header' => $header,
    'rows' => $rows,
    'caption' => $caption,);
  $output = theme("table", $tabb)
  $final_output = theme("report_page", $form, $output);
  return $final_output; 
}

function theme_report_page($form, $result = array()) {
  $output = '
    <div id="report_form">
    '. $form .'
    </div>
    <div id="report_result">
    '. $result .'
    </div>';
  return $output;
}

What am I doing wrong? I am using Drupal 7. I need to display the form and under it the table. There is nothing wrong with $form or $output. If I return them in the main_function they will display correctly.

I don't NEED a theme, I just need to display a form and table on the same page. So if it is to demanding I can skip it, and just have the form and table displayed.

I changed the main_function a bit to this:

function main_function(){
 $form = drupal_get_form("report_details_form");
 $tabb = array(
  'header' => $header,
  'rows' => $rows,
  'caption' => $caption,);
 $output = theme("table", $tabb)

$build['content'] = array(
  'this_does_not_matter_too_much2' => drupal_get_form("report_details_form"),       
  'this_does_not_matter_too_much1' => array('#markup' => $output,),);

$build['pager'] = array(
    '#theme' => 'pager',
    '#weight' => 5,
);

return $build;

A dummy table is now displayed, but just in the first call to the page, not when the page is self called after submiting the form for first time. A custom table is then created to list all the results for a SELECT. This custom table is not displayed for some reason.

2
  • 1
    drupality already answered your original question, saying you need to implement HOOK_theme in order to get your theming function theme_report_page registered in drupal's theme registry. Saying "I don't NEED a theme" indicates you didn't understand his answer fully, so I thought I'd clarify & reiterate.
    – Beebee
    Commented Jun 12, 2012 at 9:17
  • 1
    Hugo is just saying that he doesn't need a theme function to achieve what he is trying to achieve. In fact, the new code he is showing doesn't use any theme function, and it still not working as expected. It's not a matter of registering a theme function, if the new code doesn't work.
    – avpaderno
    Commented Jun 12, 2012 at 10:30

1 Answer 1

0

I think you should this in this way, so you should register you theme hook

0

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.