How to pass parameters to same form after form submission? I have created a module that creates and displays a table and with a filter element. What I would like to do is when the user enter a string into the filter can submits it, I then use that string to filter the results of the table. What I am having an issue with is how to pass that string back into the form creation function to filter the results. 

This is what I have in the submit function: 

function submission_list_form_submit($form, &amp;$form_state) {

  $filter = array();
  if (isset($form_state['values']['filter_user'])) {
    $filter['username'] = $form_state['values']['filter_user'];
  }
  return $filter;
}


Which is not right obviously. How do I get the $filter variable to be passed back into the submission_list_form function that creates the page? This is being done with Drupal 7.

Thanks.
You can use the following code, to achieve what you want.

function submission_list_form_submit($form, &amp;$form_state) {
  $filter = array();

  if (isset($form_state['values']['filter_user'])) {
    $form_state['filter']['username'] = $form_state['values']['filter_user'];
  }

  $form_state['rebuild'] = TRUE;  
}


The form building function should then check if $form_state['filter'] is set.

function submission_list_form($form, &amp;$form_state) {
  if (isset($form_state['filter'])) {
    // …
  }

  // …

  return $form;
}


If the code doesn't work, use another array index instead of $form_state['filter']; it is probable that in such case the array index conflicts with the one used by Drupal or a third-party module. I would rather prefix the array index with the short module name, to be sure to avoid conflicts with other modules or future Drupal versions. 

References


drupal_build_form()