i'm new on drupal, i've create a module that shows a form (with tableselect, list select and a submit button) the tableselect shows data from the database, but i want to filter what i want to see on the table by selecting what i want from the list select and submit. i've create the submit function (it contains the query with condition) and when i use dsm($form['tableselect'] everything works (filter works), but how can i show the result's select on the tableselect ? because it doesn't change
here's my form :
$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')
);
and this is my table select (the first one shows all records) ;
$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_titre_en_arabe_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;
}
table1 works, but it shows all records (book published and not published) now here's 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();
$rows2 = 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!')
);
}
Now how can i put result of submit on table1 to show what the query returns ??
Thanks