I want a simple filter form, and a table below it. When the user changes the option on the select form, the table automaticaly changes. I think thats done with ahah.
I want this (some things can change, like the fieldset containing the table, and other stuff):
But working.. of course..
I'm currently showing that page using one function. It's a complete mess and something like "NEVER DO THIS", but i'm researching and trying some stuff as i'm a drupal learner. This is the relevant code:
form = array();
ahah_helper_register($form, $form_state);
//query here, build $options for the select
$form['listar_veics'] = array(
'#type' => 'fieldset',
'#prefix' => '<div id="listar-veics-wrapper">',
'#suffix' => '</div>',
'#tree' => TRUE,
);
if (!isset($form_state['values']['listar_veics']['filial']))
$choice = 1;
else
$choice = $form_state['values']['listar_veics']['filial'];
$form['listar_veics']['filial'] = array(
'#type' => 'select',
'#title' => "Listar veículos da filial",
'#options' => $filiais,
'#default_value' => $choice,
'#ahah' => array(
'event' => 'change',
'path' => ahah_helper_path(array('listar_veics')),
'wrapper' => 'listar-veics-wrapper',
'method' => 'replace',
),
);
//query for the rows i wanna show
//building $data array, the rows array
//building $header, as an array of strings
$table = theme_table($header, $data);
$page = drupal_render($form);
$page .= $table;
return $page;
So in this code, drupal will only replace the form itself, when i change the option on the select, it shows the new value on the select, but the table isnt rendered again thus not changing.
Thanks, apreciate every suggestion.
I recommend looking at the views module.
http://drupal.org/project/views
With that installed, you can create a custom query.
For more information might I recommend http://gotdrupal.com/videos/drupal-views-tutorial.
If you want neater exposed fields I might also recommend http://drupal.org/project/better_exposed_filters