How do I rebuild table data on submit? I am using Drupal 7, I am using form API to generate a table with select option filters. The data from the table is from an external API.

The table loads as it should, the drop down selection loads as should. When I select an option from the drop down section I am trying to pass the selected value into the URL of the external API and rebuild the table using the new URL but the table does not get rebuilt, instead the page just refreshes, the selected option is updated in the drop down selection. I have tested and think that the URL variable is updated to include the select option but the table does not get rebuilt. 

This is the module

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

$form['type_options'] = array(
  '#type' =&gt; 'value',
  '#value' =&gt; $options
);

$form['Title'] = array(
  '#title' =&gt; $title,
  '#type' =&gt; 'select',
  '#options' =&gt; $form['type_options']['#value'],
  '#default_value' =&gt; isset($form_state['storage']['Title']) ? $form_state['storage']['Title'] : '',
);

$form['submit'] = array(
  '#type' =&gt; 'submit',
  '#value' =&gt; t(“Filter”),  
);

//Get fromtable data from API
if (!empty($form_state['storage']['Title'])) {
 $filter = preg_replace('/\s+/', '+', $form_state['storage']['Title']);
  $url  = $api.'&amp;filter='.$filter;
} else {
  $url = $api;
}
$json = file_get_contents($url);
$data = json_decode($json,true);
$rows = $data[data];

//Set paging items for formtable
$per_page = 30;
$current_page = pager_default_initialize(count($rows),$per_page);
$chunks = array_chunk($rows, $per_page, TRUE);
$form['table'] = array(
  '#theme' =&gt; 'table',
  '#header' =&gt; $header,
  '#rows' =&gt; $chunks[$current_page],
  '#empty' =&gt; $empty,
  '#pager' =&gt; array('quantity' =&gt; 12)
);      

$form['pager'] = array(
  '#theme' =&gt; 'pager',
);

return $form;
}

function mymodule_form_submit($form, &amp;$form_state) {
  $form_state['storage']['Title'] = $form_state['values']['Title'];
  $form_state['rebuild'] = TRUE;  
}


Thanks for any help
Your code should work fine from what I see. You can print the $url value to see what really is passed to API. Please note that $form_state['storage']['Title'] will contain the key, not value - maybe that's the problem?

Plus, you don't need to use storage in this case. When using $form_state['rebuild'] you can just use $form_state to pass variables, like this:

function mymodule_form($form, &amp;$form_state) {
  $storage_val = isset($form_state['values']['title']) ? $form_state['values']['title'] : 'nothing stored yet';

  $form['message'] = array(
    '#markup' =&gt; t('Stored value: %storage_val', array('%storage_val' =&gt; $storage_val)),
  );

  $options = array(
    'opt1' =&gt; 'option1',
    'opt2' =&gt; 'option2',
    'opt3' =&gt; 'another option',
  );

  $form['title'] = array(
    '#title' =&gt; 'Select option',
    '#type' =&gt; 'select',
    '#options' =&gt; $options,
    '#default_value' =&gt; isset($form_state['values']['title']) ? $form_state['values']['title'] : '',
  );

  $form['submit'] = array(
    '#type' =&gt; 'submit',
    '#value' =&gt; t('Filter'),
  );

  return $form;
}

function mymodule_form_submit($form, &amp;$form_state) {
  $form_state['rebuild'] = TRUE;
}