2

From a custom module in Drupal 7 I am trying to load a template after I submit and process my form.

I can load the theme fine from a page callback:

function mymodule_theme() {
  $themes = array(
    'mymodule_report' => array(
      'template' => 'themes/mymodule_report',
      'arguments' => array(),
    ),
  );
  return $themes;
}

function mymodule_menu() {
  $items = array();       
  $items['reports/performance'] = array(
    'title' => 'My Module Performance Report',
    'page callback' => '_mymodule_report',
    'access arguments' => array('mymodule_client'),
  );
  return $items;
}

function _mymodule_report() {
  return theme('mymodule_report');
}

All of that works fine (e.g I can go to www.mysite.com/reports/performance and my tpl loads.). The problem is when i submit a form, after I process the form I want to pass the form data to the template, and load the same template page.

I modified the hook_theme like this:

function mymodule_theme() {
  $themes = array(
    'mymodule_report' => array(
      'template' => 'themes/mymodule_report',
      'variables' => array('parameters' => NULL),
    )
  );
  return $themes;
}

And in my submit handler for my form after I gathered all my form values into an object ($submission), I added this at the end:

 return theme('mymodule_report', array('parameters' => $submission));

All that happens is my form reloads...what am I missing?

1
  • @Jack-PL while editing to improve formatting is usually a good thing, editing code should be avoided - except putting it into a code block if it isn't. Things like proper line breaks can be cause and solution to errors, so only OP is really supposed to edit them.
    – Mołot
    Commented Sep 3, 2013 at 12:30

1 Answer 1

1

So I found a solution that works...of course if there's another or better way, I'd love to know.

I added this to my form:

  if (!empty($form_state['nnjob_mtbf']['mtbf_results'])) {
    $form['result'] = array(
      '#markup' => $form_state['nnjob_mtbf']['mtbf_results'],
    );
  }

And then to my form submit handler:

  $form_state['nnjob_mtbf']['mtbf_results'] = theme('nnreport_client_perf_report', array('parameters' => $submission));
  $form_state['rebuild']=TRUE;

And voila, template loads like a champ.

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.