Drupal提交更改tableselect的查询

时间:2015-06-19 21:29:28

标签: php forms drupal

我是关于drupal的新手,我创建了一个模块,显示一个带有选择,按钮提交的表单,并且我有一个表选择列出一些记录(来自数据库)。 tableselect有效,它列出了所有记录,但我希望"过滤"通过选择列表(和提交)选择我想要查看的内容,选择此表上的记录。当我在选择列表中选择并且我提交时,tableselect不会改变但是如果我执行dsm($ form [' tableselect']),它表示tableselect包含db_query返回的内容。

这是我的表格:

 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;

这是我的提交功能:

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!')
  );   
   }

由于

0 个答案:

没有答案