You are here

function email_contact_mail_page_form_submit in Email Contact 7

Process the site-wide contact page form submission.

1 string reference to 'email_contact_mail_page_form_submit'
email_contact_mail_page_form in ./email_contact.module
Contact form.

File

./email_contact.module, line 419
File name: email_contact.module.

Code

function email_contact_mail_page_form_submit($form, &$form_state) {
  $object_type = $form_state['values']['object_type'];
  $object_id = $form_state['values']['object_id'];
  $field_name = $form_state['values']['field_name'];
  $emails = unserialize($form_state['values']['emails']);

  // Load entity.
  $objects = entity_load($object_type, array(
    $object_id,
  ));
  $object = $objects[$object_id];
  $object_info = entity_get_info($object_type);

  // E-mail address of the sender: as the form field is a text field,
  // all instances of \r and \n have been automatically stripped from it.
  $from = $form_state['values']['mail'];
  $params['object'] = $object;
  $params['subject'] = $form_state['values']['subject'];
  $params['name'] = $form_state['values']['name'];
  $params['default_message'] = $form_state['widget_settings']['default_message'];
  $params['message'] = $form_state['values']['message'];
  $path = "";
  if (isset($object_info['path callback']) && function_exists($object_info['path callback'])) {
    $path = $object_info['path callback']($object);
  }
  $params['url'] = url($path, array(
    'absolute' => TRUE,
  ));

  // Send the e-mail to the recipients.
  drupal_mail('email_contact', 'contact', implode(', ', $emails), language_default(), $params, $from);

  // Log the operation.
  if ($GLOBALS['user']->uid != 1) {
    flood_register_event('email');
  }
  watchdog('mail', '%name-from sent an e-mail at %form.', array(
    '%name-from' => $form_state['values']['name'],
    '%form' => url($_GET['q'], array(
      'absolute' => TRUE,
    )),
  ));
  drupal_set_message(t('Your message has been sent.'));
  $form_state['redirect'] = '<front>';
  if (!empty($form_state['widget_settings']['redirection_to'])) {
    switch ($form_state['widget_settings']['redirection_to']) {
      case 'current':
        $form_state['redirect'] = current_path();
        break;
      case 'custom':
        $form_state['redirect'] = $form_state['widget_settings']['custom_path'];
        break;
      default:
        $form_state['redirect'] = $path;
        break;
    }
  }
}