How do I get values of checkboxes? I'm using Drupal 7 and have added checkboxes to a node.

$results = query();

foreach ($results as $result) {
  $name = $result['name'];
  $resultarray[$result['id']] = $name; 
}

$form['friends'] = array(
  '#title' =&gt; "results",
  '#type' =&gt; 'checkboxes',
  '#options' =&gt; $resultarray,
);


On my node the checkboxes show. 

Now I'm struggling to get the values of selected checkboxes.

function friendmodule_form_submit($form, &amp;$form_state) {

  $friends = $form_state['values']['friends'];

  // do what ever with $friends 
}


But nothing displays. I've tried echo $friends, print_r, display them as a Drupal message, but nothing is showing. 

What should I do to get the values of selected checkboxes?
Assuming that your $resultarray variable in the form actually has some data in it, this code will get you a list of the ids that have been selected:

function friendmodule_form_submit($form, &amp;$form_state) {   
  $friend_ids = array_filter($form_state['values']['friends']);
}


When a checkboxes element is submitted all of the original option keys will be in the $form_state['values']'friends'] array, but only the ones that have been selected will have a positive value; the rest will have a value of zero, so you need to use array_filter() to extract only the IDs for options that have been selected.

Also, at the moment you have a syntax error in your submit function (an extra closing )), maybe that's what is causing the error.