You are here

function nodeformsettings_settings_submit in Node and Comments Form Settings 7.2

Same name and namespace in other branches
  1. 6.3 nodeformsettings.module \nodeformsettings_settings_submit()
  2. 6.2 nodeformsettings.module \nodeformsettings_settings_submit()
  3. 7.3 nodeformsettings.module \nodeformsettings_settings_submit()

Submit callback for the node form alter.

See also

nodeformsettings_form_alter()

1 string reference to 'nodeformsettings_settings_submit'
nodeformsettings_form_alter in ./nodeformsettings.module
Implements hook_form_alter().

File

./nodeformsettings.module, line 170

Code

function nodeformsettings_settings_submit($form, &$form_state) {

  // Get the values sent from the form and save them in $values.
  $values = $form_state['values'];

  // dprint_r($values);
  // Save the value of $values['var'] in $name. This variable will
  // be used to define the name in variable_set($name, $values)
  // This will be something like nodeformsettings_contenttype.
  $name = 'nodeformsettings_' . $values['var'];

  // Get the elements from the function and loop to get only the keys, not the values.
  $elements = nodeformsettings_elements_default();
  foreach ($elements as $k => $v) {

    // Build the $ignore array with only the keys ($k).
    $ignore[] = $k;
  }

  // Add to the $ignore array the $name.
  $ignore[] = $name;

  // Loop thought the array of $values to unset everything but our values in $ignore.
  foreach ($values as $key => $value) {

    // If the key IS NOT in the $ignore array, then unset that value.
    if (!in_array($key, $ignore)) {
      unset($values[$key]);
    }
    else {

      // Build the $data array wich we will send to the variable_set function.
      $data[$key] = $value;
    }
  }
  variable_set($name, $data);
  if (isset($values['var'])) {

    // Purge all variables created by hook_node_type.
    nodeformsettings_purge($values['var']);
  }
}