I'm new on drupal, i've create a module that shows a form with select, button submit and i've got a tableselect that lists some records (from database). the tableselect works and it's listing all records, but i want to "filter" records on this tableselect by selecting what i want to see with select list (and submitting). when i choose something in the select list and i submit, the tableselect dont change but if i execute a dsm($form['tableselect']) it said that tableselect contains what the db_query returns.
here is my form :
function myBook_form ($form, &$form_state){
$form = array();
$form['options_state'] = array(
'#type' => 'value',
'#value' => array (
'all'=>t('All'),
'Valid'=>t('Valid'),
'published'=>t('published'),
'not published'=>t('not published')
)
);
$form['state_book'] = array(
'#type' => 'select',
'#title' => t('state :'),
'#options' => $form['options_state']['#value'],
);
// filter submit button
$form['filter'] = array(
'#type' => 'submit',
'#value' => t('filter')
);
}
$header = array(
'book_title' => t('title'),
'book_state' => t('state'),
);
$sql = db_select('field_data_field_title','ta');
$sql->join('field_data_field_state','st','st.entity_id = ta.entity_id');
$sql
->fields('ta', array('field_title_value','entity_id'))
->fields('st',array('field_state_value'));
$result = $sql->execute();
$rows = array();
foreach ($result as $res){
$rows [] = array(
'book_title' => l($res->field_title_value, 'node/'.$res->entity_id),
'book_state' => $res->field_state_value
);
}
$form['table1'] = array(
'#type' => 'tableselect',
'#header' => $header,
'#options' => $rows,
'#empty' => t('empty !'),
);
return $form;
here is my submit function :
function book_form_submit($form, &$form_state){
$cond = $form_state['values']['state_book'];
$header = array(
'book_title' => t('title'),
'book_state' => t('state'),
);
$sql = db_select('field_data_field_title','ta');
$sql->join('field_data_field_state','st','st.entity_id = ta.entity_id');
$sql
->fields('ta', array('field_title_value'))
->fields('st',array('field_state_value'));
$sql->condition('st.field_state_value', $cond, '=');
$quer = $sql->execute();
$rows = array();
foreach ($quer as $q){
array_push($rows, array(
'book_title' => $q->field_title_value,
'book_state' => $q->field_state_value,
));
}
$form['table2'] = array(
'#type' => 'tableselect',
'#header' => $header,
'#options' => $rows,
'#empty' => t('empty!')
);
}
Thanks