how to get the submitted value of tableselect in drupal 7 -


function test($form, &$form_state){    $form = array();     $header = array(.............);     $values = array(.............);     $form['table'] = array(       '#type' => 'tableselect',       '#header' => $header,       '#options' => $rows,       '#multiple' => $ischeckbox,       '#empty' => t('no users found'),     );     $form['submit'] = array(       '#type' => 'submit',       '#value' => t('submit'),     );   return $form;  } // end of function test()  function test_submit($form, &$form_state){  $selected = $form_state['values']['table'];  drupal_set_message($selected)  // displays array index (0,1,2 etc)  return; } 

how selected table row values in drupal form. need assistance on issue. appreciated.

what in $selected index of $rows have selected in table. values in $rows need use index have in $selected.

i created easy example how here:

function test($form, &$form_state) {     $form = array();      $header = array(         'first_name' => t('first name'),         'last_name'  => t('last name'),     );      $rows = array(         // these index in submit function. index unique $key in database.         '1' => array('first_name' => 'mario',          'last_name' => 'mario'),         '2' => array('first_name' => 'luigi',          'last_name' => 'mario'),         '3' => array('first_name' => 'princess peach', 'last_name' => 'toadstool'),     );      $form['table'] = array(        '#type' => 'tableselect',        '#header' => $header,        '#options' => $rows,        '#multiple' => true,        '#empty' => t('no users found'),     );      $form['submit'] = array(         '#type' => 'submit',         '#value' => t('submit'),     );      return $form; } // end of function test()  function test_submit($form, &$form_state) {     // function should not duplicated easier do.     $rows = array(         '1' => array('first_name' => 'mario',          'last_name' => 'mario'),         '2' => array('first_name' => 'luigi',          'last_name' => 'mario'),         '3' => array('first_name' => 'princess peach', 'last_name' => 'toadstool'),     );      $names = array();     // remove names has not been checked     $selected_names = array_filter($form_state['values']['table']);      // iterate on indexes selected data original array     foreach ($selected_names $index ) {         array_push($names, $rows[$index]);     }      foreach($names $name) {         drupal_set_message($name['first_name'] . ' ' . $name['last_name']);     } } 

Comments

Popular posts from this blog

android - Gradle sync Error:Configuration with name 'default' not found -

java - Andrioid studio start fail: Fatal error initializing 'null' -

html - jQuery UI Sortable - Remove placeholder after item is dropped -