You are here

function mailing_list_form_submit in Mailing List 7

Same name and namespace in other branches
  1. 6 mailing_list.admin.inc \mailing_list_form_submit()

Submit handler for the add / rename mailing list form.

1 string reference to 'mailing_list_form_submit'
mailing_list_form in ./mailing_list.admin.inc
Form for adding / renaming a mailing list.

File

./mailing_list.admin.inc, line 236
Mailing list admin UI.

Code

function mailing_list_form_submit($form, &$form_state) {

  // @todo: put these in variables and on the settings page.
  $messages = array();
  $messages['update'] = array(
    'pass' => 'Renamed mailing list %name',
    'fail' => 'Failed to update mailing list %name',
  );
  $messages['insert'] = array(
    'pass' => 'Created mailing list %name',
    'fail' => 'Failed to create mailing list %name',
  );

  // List object to save
  $list = new StdClass();
  $list->name = $form_state['values']['name'];
  if (!empty($form_state['values']['mlid'])) {

    // Update operation
    $list->mlid = $form_state['values']['mlid'];
    $active_messages = $messages['update'];
  }
  else {
    $active_messages = $messages['insert'];
  }
  try {
    mailing_list_save($list);
    drupal_set_message(t($active_messages['pass'], array(
      '%name' => $form_state['values']['name'],
    )));
    watchdog('mailing_list', $active_messages['pass'], array(
      '%name' => $form_state['values']['name'],
    ), WATCHDOG_NOTICE, l(t('view'), 'admin/structure/mailing-list/' . $list->mlid));
  } catch (PDOException $e) {
    drupal_set_message(t($active_messages['fail'], array(
      '%name' => $form_state['values']['name'],
    )), 'error');
    watchdog('mailing_list', $active_messages['fail'], array(
      '%name' => $form_state['values']['name'],
    ), WATCHDOG_NOTICE);
  }
}