You are here

function privatemsg_new_submit in Privatemsg 6.2

Same name and namespace in other branches
  1. 7.2 privatemsg.pages.inc \privatemsg_new_submit()
  2. 7 privatemsg.pages.inc \privatemsg_new_submit()

Submit callback for the privatemsg_new form.

1 call to privatemsg_new_submit()
privatemsg_forward_form_submit in privatemsg_forward/privatemsg_forward.module
Submit function for forward form.
1 string reference to 'privatemsg_new_submit'
_privatemsg_form_base_fields in ./privatemsg.pages.inc
Returns the common fields of the reply and new form.

File

./privatemsg.pages.inc, line 547
User menu callbacks for Privatemsg.

Code

function privatemsg_new_submit($form, &$form_state) {

  // Clear form_state storage so that it does not rebuild.
  $form_state['storage'] = NULL;
  $status = _privatemsg_send($form_state['validate_built_message']);

  // Format each recipient.
  $recipient_names = array();
  foreach ($form_state['validate_built_message']['recipients'] as $recipient) {
    $recipient_names[] = privatemsg_recipient_format($recipient);
  }
  if ($status !== FALSE) {
    _privatemsg_handle_recipients($status['mid'], $status['recipients']);
    drupal_set_message(t('A message has been sent to !recipients.', array(
      '!recipients' => implode(', ', $recipient_names),
    )));

    // Only redirect on new threads.
    if ($status['mid'] == $status['thread_id'] || variable_get('privatemsg_default_redirect_reply', FALSE)) {
      $redirect = variable_get('privatemsg_default_redirect', '<new-message>');
      if ($redirect == '<new-message>') {

        // Forward to the new message in the thread.
        $form_state['redirect'] = array(
          privatemsg_get_dynamic_url_prefix() . '/view/' . $status['thread_id'],
          NULL,
          'privatemsg-mid-' . $status['mid'],
        );
      }
      elseif (!empty($redirect)) {
        $form_state['redirect'] = $redirect;
      }
    }

    // Replace [new-message] placeholder with actual destination.
    if (!empty($_REQUEST['destination']) && $_REQUEST['destination'] == '[new-message]') {

      // url() can not be used because it does create an path with base path and
      // prefix.
      $_REQUEST['destination'] = urlencode(privatemsg_get_dynamic_url_prefix() . '/view/' . $status['thread_id'] . '#' . 'privatemsg-mid-' . $status['mid']);
    }
  }
  else {
    drupal_set_message(t('An attempt to send a message <em>may have failed</em> when sending to !recipients.', array(
      '!recipients' => implode(', ', $recipient_names),
    )), 'error');
  }
}