How do I use a submit callback on a Drupal admin settings form? I'm using this code to make my admin form:

function custom_orders_admin(){
  $form = array();

  $form['custom_ignore_terms']['ignore_terms'] = array(
    '#type' =&gt; 'checkboxes',
    '#title' =&gt; t('Don\'t display these'),
    '#default_value' =&gt; variable_get('custom_ignore_terms', array()),
    '#options' =&gt; drupal_map_assoc($termTypes),
    '#description' =&gt; t("Choose the terms you do not want displayed."),
    '#required' =&gt; FALSE,
  );

  return system_settings_form($form);
}


But I notice that if I do this:

function custom_orders_admin_submit($form, &amp;$form_state) {
  exit(var_dump($form_state));
}


I can't exit. I'm guessing this is because system_settings_form() takes care of submitting. How do I get my control back? I need to do some custom processing in that _submit handler...
The default submit handler of $form_id . '_submit' only fires if no other submit handlers have been set.

Because system_settings_form() sets a submit handler, the default handler doesn't fire, so you have to specify it if you want to use it.

You can do so like this:

/**
 * A custom form.
 */
function custom_form() {
  $form = array();

  $form['custom_form_field'] = array(
    '#type' =&gt; 'textfield',
    '#title' =&gt; t('Custom form field'),
    '#default_value' =&gt; variable_get('custom_form_field', ''),
  );

  // Set a submit handler manually because the default submit handler
  // gets overridden by the system_settings_form() submit handler.
  $form['#submit'][] = 'custom_form_submit';

  return system_settings_form($form);
}

/**
 * Submit handler for the custom form.
 */
function custom_form_submit($form, &amp;$form_state) {
  // Submit code here.
}


Adding your submit handler like this means yours will run before the system_settings_form() submit handler.

If you want yours to run after, instead of:

// Set a submit handler manually because the default submit handler
// gets overridden by the system_settings_form() submit handler.
$form['#submit'][] = 'custom_form_submit';

return system_settings_form($form);


Do:

$form = system_settings_form($form);
$form['#submit'][] = 'custom_form_submit';
return $form;


Make sure not to do this though:

$form = system_settings_form($form);
$form['#submit'] = array('custom_form_submit');
return $form;


because that would overwrite the system_sttings_form() submit handler, which would defeat the purpose of using the system_settings_form() function in the first place.