How do I programmatically retrieve the inputs from a form?
You can use the element_children() function to grab all of the child elements within a particular element (including a form element). The thing with Drupal forms is that often all elements are not on the same level of the array, so you'll need to make a recursive function to get them all reliably. This is untested but should give you a place to start:

function _element_children_recursive(&amp;$element) {
  $names = array();

  foreach (element_children($element) as $element_key) {
    $names[] = $element_key;
    $names = array_merge($names, _element_children_recursive($element[$element_key]));
  }

  return $names;
}

$all_element_names = _element_children_recursive($form);


There's even one further caveat to this...since form elements can be on different levels you might well end up with two identically named keys. This is perfectly valid in Drupal so you'll probably want to do a bit of checking in the recursive function to avoid duplicates.