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, &$form_state) {
$form['type_options'] = array(
'#type' => 'value',
'#value' => $options
);
$form['Title'] = array(
'#title' => $title,
'#type' => 'select',
'#options' => $form['type_options']['#value'],
'#default_value' => isset($form_state['storage']['Title']) ? $form_state['storage']['Title'] : '',
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t(“Filter”),
);
//Get fromtable data from API
if (!empty($form_state['storage']['Title'])) {
$filter = preg_replace('/\s+/', '+', $form_state['storage']['Title']);
$url = $api.'&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' => 'table',
'#header' => $header,
'#rows' => $chunks[$current_page],
'#empty' => $empty,
'#pager' => array('quantity' => 12)
);
$form['pager'] = array(
'#theme' => 'pager',
);
return $form;
}
function mymodule_form_submit($form, &$form_state) {
$form_state['storage']['Title'] = $form_state['values']['Title'];
$form_state['rebuild'] = TRUE;
}
Thanks for any help