I have a simple select form that I want to use as a "Sort By" handler. When user chooses a different option I want it to change the query and display the new results. E.G. sort by duration ASC or sort by duration DESC.
This is my form:
function mortgage_multi_view_sort_form($form, &$form_state) {
$form = array();
$sortOptions = array(
1 => t('Mortgage Duration: Shortest to Longest'),
2 => t('Mortgage Duration: Longest to Shortest'),
);
$form['mortgage_sort'] = array(
'#type' => 'select',
'#title' => t('Sort By'),
'#options' => $sortOptions,
'#default_value' => 1,
'#required' => TRUE,
'#ajax' => array(
'event' => 'change',
'callback' => 'ajax_select_callback',
//'wrapper' => 'replace_model_div',
'method' => 'replace',
//'effect' => 'fade',
),
);
return $form;
}
When they change this to Longest to Shortest I want to asynchronously display the mortgages in reverse order. Is this best to do in the callback function?
My callback function (currently):
function ajax_select_callback($form, &$form_state){
switch($form['mortgage_sort']){
case 1:
$result = db_query('SELECT * FROM {mortgage_database} ORDERBY duration DESC');
displayMortgages($result);
break;
case 2:
$result = db_query('SELECT * FROM {mortgage_database} ORDERBY duration ASC');
displayMortgages($result);
break;
}
}
In my displayMortgages() function it just takes the entire query and displays it in a table. How do I get this information to block['content'] from my displayMortgages() now?