You are here

function commentformsettings_settings_submit in Node and Comments Form Settings 7.3

Same name and namespace in other branches
  1. 6.3 commentformsettings/commentformsettings.module \commentformsettings_settings_submit()
  2. 6.2 commentformsettings/commentformsettings.module \commentformsettings_settings_submit()
  3. 7.2 commentformsettings/commentformsettings.module \commentformsettings_settings_submit()

Submit callback for the node form alter.

See also

commentformsettings_form_alter()

1 call to commentformsettings_settings_submit()
commentformsettings_set_default_to_all in commentformsettings/commentformsettings.module
Function to handle submit for setting default for all content types.
1 string reference to 'commentformsettings_settings_submit'
commentformsettings_form_alter in commentformsettings/commentformsettings.module
Implements hook_form_alter().

File

commentformsettings/commentformsettings.module, line 182

Code

function commentformsettings_settings_submit($form, &$form_state) {

  // Get the values sent from the form and save them in $values.
  $values = $form_state['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 commentformsettings_contenttype.
  $name = 'commentformsettings_' . $values['var_comments'];

  // Get the elements from the function and loop to get only the keys, not the values.
  $elements = commentformsettings_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_comments'])) {

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