Is "system_settings_form" voodoo? A friend just showed me system_settings_form in action in a configuration file for a form.

The code in question looks like this (simplified).

function my_module_generateAdminForm($form){
  $form = array();
  $form['super_secret_password'] = array(
    '#type' =&gt; 'textfield',
    '#title' =&gt; t('Headline'),
    '#default_value' =&gt; variable_get('super_secret_password','password'),
  );
  system_settings_form($form);
}


system_settings_form adds in submit buttons and handles the form submission, saving the variables. It also adds a "Reset to default" button - that resets all the variable to the default.

I basically guessed what it does because there's not a whole lot of documentation out there and my friend doesn't know exactly what it does either. My question is how does it know the variables to save/reset? Aren't I just passing an array?

Also is there any other magic in system_settings_form that I should know about?
See system_settings_form and system_settings_form_submit for implementation details. In Drupal 7 Reset to Default button is removed from System Settings form .

function system_settings_form($form) {
  $form['actions']['#type'] = 'actions';
  $form['actions']['submit'] = array(
    '#type' =&gt; 'submit',
    '#value' =&gt; t('Save configuration'),
  );

  if (!empty($_POST) &amp;&amp; form_get_errors()) {
    drupal_set_message(t('The settings have not been saved because of the errors.'), 'error');
  }
  $form['#submit'][] = 'system_settings_form_submit';
  // By default, render the form using theme_system_settings_form().
  if (!isset($form['#theme'])) {
    $form['#theme'] = 'system_settings_form';
  }
  return $form;
}


System_settings_form :

Add's save configuration Submit button and submit callback to system_settings_form_submit function.

system_settings_form_submit:

function system_settings_form_submit($form, &amp;$form_state) {
  // Exclude unnecessary elements.
  form_state_values_clean($form_state);

  foreach ($form_state['values'] as $key =&gt; $value) {
    if (is_array($value) &amp;&amp; isset($form_state['values']['array_filter'])) {
      $value = array_keys(array_filter($value));
    }
    variable_set($key, $value);
  }

  drupal_set_message(t('The configuration options have been saved.'));
}


Iterates through all form elements and sets variables for each form element with key as form element key and value as user submitted form  element value read using $form_state['values']

So, it's just a form with submit handler that sets variables for all form values using variable_set function.