I’m struggling with how to get a form-submit to return the results of a database select-query. I can build the form and the submit-function does the select-query to collect the results and builds a render-array:

$table = array(
    '#theme' => 'table',
    '#header' => array(t($field_1), t($field_2)),
    '#rows' => $tableRowS,

However I can’t figure out how to get drupal to render this table instead of just rebuilding and showing the empty form again. I’ve examined the concept of redirect but don’t see a way of passing the table to the redirected page.

Any help would be appreciated.


I don't think you can return a themed table on form submit. Instead, what I suggest is to use $_SESSION variable to store the form field values to query the database and redirect to a URL. In the callback function of the URL query the database and return the themed page.


function mymodule_myform_submit($form, $form_state){
   $_SESSION['somevar'] = $form_state['values']['somefield'];

And in the URL callback function get the value of the session variable $somevar = $_SESSION['somevar'];

  • Downvoters please provide a valid reason. – WebLink Jan 17 '17 at 18:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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