Drupal 7 Request a database and display the results after submitting the form to the user module

function mymodule_search_form($form, &$form_state) {

  $form..... define the form here

  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => 'Search',
  );

  return $form;
}

function mymodule_search_form_submit($form, &$form_state) {

  //process the form and get result 
  $output = this is the result with a table of data.
  //I want to display the result table here.

 //Now I can only use drupal message to display on top.
 drupal_set_message($output);

  return;
}

So basically I want to have a form to search for something from the database. After that, click "Submit" to search and get the result.

I want to show the result only in the form on the same page of the form. Do not go to another page, only on the original page of the form.

The form can be clean / reset in its original state, which is good.

http://drupal.org/node/542646 This discussion is what I want, but there is no solid result / solution.

+5
source share
1 answer

$form_state, , , .

function mymodule_search_form($form, &$form_state) {

  $form..... define the form here

  if (!empty($form_state['results_table'])) {
    $form['results_table'] = array('#markup' => $form_state['results_table']);
  }

  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => 'Search',
  );

  return $form;
}

function mymodule_search_form_submit($form, &$form_state) {
  $form_state['results_table'] = function_to_get_table();
  $form_state['rebuild'] = TRUE;
}
+9

All Articles