Multiple submit buttons: Which one was pressed? This may be a duplicate of the following: Multiple form submit, but I am unable to figure out how the answer applies to my situation.  So here is my go at asking this (I admit) quite similar question:

I have a table with a row of data, each row has a submit button.  It may look something like this:

$form['f'] = array();
foreach ($rows as $row) {
  $form['f'][$row['nid']] = array();
  $form['f'][$row['nid']]['nid'] = array(
    '#markup' =&gt; $row['nid'],
  );
  $form['f'][$row['nid']]['submit'] = array(
    '#type' =&gt; 'submit',
    '#value' =&gt; t('sumbit'),
    '#submit' =&gt;  array('f_submit'),
  );
}


I.e. the form consists of a sequence of rows, extracted from the database,  I want to create a submit callback that picks up the value of the corresponding nid field and prints out its value.   I guess I am asking what to put where the comment below is.

function f_submit($form, &amp;$form_state) {
  // Here I want to print the value of the relevant nid field
}
Data about clicked button is stored in $form_state['triggering_element']. You can get the node ID by looking at $form_state['triggering_element']['#parents']. In your case the node ID would be the second item in the parents array. Please note that the name attribute of the field definition needs to be defined and unique. Otherwise the triggering element will point to the last submit button on the form. I would alter your code as follows:

$form['f'] = array();
foreach ($rows as $row) {
  $form['f'][$row['nid']] = array();
  $form['f'][$row['nid']]['nid'] = array(
    '#markup' =&gt; $row['nid'],
  );
  $form['f'][$row['nid']]['submit'] = array(
    '#type' =&gt; 'submit',
    '#value' =&gt; t('sumbit'),
    '#name' =&gt; 'submit-' . $row['nid'],
    '#submit' =&gt;  array('f_submit'),
  );
}


Good way to view $form_state is to install the Devel module (for krumo()) and then putting krumo($form_state);drupal_exit(); to top of the submit handler. This will print out a nice structured tree of data.