1
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 to get the selected table row values in Drupal form. Need assistance on the issue. Any help would be appreciated.

1
  • you can go thru this array using PHP foreach function
    – Andrew
    Commented Jul 20, 2015 at 10:19

1 Answer 1

0

You can exclude unselected options with array_filter, e.g.

$selected = array_filter($form_state['values']['table']);
4
  • Thank you Clive :) But $selected returns only the selected array index. How to get array values in Submit. Please assist further
    – Sudee
    Commented Jul 20, 2015 at 10:28
  • 1
    One usually works with values and not labels in form submissions, but if you absolutely need the labels then you'll need to loop through $form['table']['#options'] and match that up against what you now have in $selected
    – Clive
    Commented Jul 20, 2015 at 10:30
  • I'm a newbie in Drupal. Will you please elaborate
    – Sudee
    Commented Jul 20, 2015 at 11:16
  • 1
    That's just basic PHP, nothing Drupal-specific about it
    – Clive
    Commented Jul 20, 2015 at 11:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.