I can create a form with a submit button. Now below the submit button after the user submits some input data, I want to display the results of a report that I create by querying the database using the input variables that the user input on the form.

I can recreate the input variables that the user submitted by going to nameofmodule_form_submit() and typing $form_state['rebuild'] = TRUE;

Now I have several questions:

1. I guess I'll test whether the form has been submitted by using if (isset($form_state['values'])). Will that work?
2. Do I create the db_select query in hook_form_submit(), or do I do it somewhere else?
3. Let's say that I want this report to be a table, and I iterate through the results of the db_select query to create the table HTML. How do I add that table HTML to the HTML of the form page? Do I just return $html; in mymodule_form_submit? mymodule_form_alter?

Comments

nevets’s picture

Is the data something views can be used to list? If using views will an exposed form/filter work?

MrSnrub’s picture

No, Views will not work.

logicp’s picture

I am also interested in learning about this! This might not be the "drupal way" of doing things, but it would be both useful and interesting as a development tool.

anbarasan.r’s picture

1. Call a normal page callback function instead of calling a form callback.
2. Inside that callback write your query to display results and a form callback function there.

Ex.
function example_callback() {
$vars['header'] = array('Name', 'User Id');
$vars['empty'] = t('No Record Found!');
$vars['rows'] = array();
$user_add_form = drupal_get_form('add_form');
$output = drupal_render($user_add_form);
$output .= theme('table', $vars);
$output .= theme('pager');
return $output;
}
function add_form() {
//form fields
}