I am creating a module using the Form API. The form is intended to provide data for querying a database and displaying a table based on the query. When the user submits, I want both the form and the data table to render on the same page so that the user can keep changing criteria and viewing the result.

I am assuming I can do something like this:

theme_myform ($form) {
$output = drupal_render($form);
$output .= build_table();
return $output;
}

However, before building the table and appending it to the form, I need to test to see if the form has been successfully posted and I will also need to capture some of the posted values to run the query for producing the table. How do I get access to $form_values (or something similar) in my theme function.

I am sure this is a simple thing, but the only stuff I have been able to find online is instructions on adding to the form itself depending on previous submissions.

Thanks in advance for the help.

Comments

brooklynwebguy’s picture

Maybe other folks will find this useful. Also looking for alternative routes to the same result. Basically I am trying to append a report (in a table) to a successfully submitted user form.

Let's assume my form is called myform.

I added this to my module

  function myform($form_values=NULL) {
    //my normal form building code here then. . .  
    //I check to see if $form_values have been passed via a successful previous submission. 
    //The passing of $form_values is reliant on the redirect and multistep settings further down
    if (isset($form_values)) {
       
      //create hidden fields capturing the data I need for producing the table;
      $form['posted_val1'] = array(
          '#type' => 'hidden',
          '#value' => $form_values['val1'],
        ); 
    }
    
     //crucial bit here to insure successfully posted values get passed the next time around
        $form['#multistep'] = TRUE;
        $form['#redirect'] = FALSE;

   //remaining form building stuff like submit button goes here
       return $form;
   }

   //my theme function for rendering the form with the table appended. 
  function theme_myform($form) {
    $output = drupal_render($form);
    
    //test for posted value needed for querying data and building table
    if (isset($form['posted_val1]['#value'])) {

      //append result of table building function to form
      $output .= build_table($form['posted_val1]['#value']);
    }
    return $output;
 }

 
pcambra’s picture

I was looking for something similar for Drupal 6 and I found that this can be done by setting a parameter in $form_state:

$form_state['storage'] = TRUE;