You are here

function webform_submit in Webform 5.2

Same name and namespace in other branches
  1. 5 webform.module \webform_submit()
  2. 6.2 webform.module \webform_submit()

Implementation of hook_submit().

File

./webform.module, line 816

Code

function webform_submit(&$node) {

  // Add the conditional e-mail recipients to components.
  if ($node->nid) {
    $original_node = node_load($node->nid);
    foreach ($original_node->webform['components'] as $cid => $component) {
      if (!isset($node->webform['components'][$cid])) {
        $node->webform['components'][$cid] = $component;
      }
      if (isset($node->webform['email_components'][$cid])) {
        $node->webform['components'][$cid]['extra']['email'] = $node->webform['email_components'][$cid];
      }
    }
  }
  unset($node->webform['email_components']);

  // Merge the e-mail name, address, and subject options into single values.
  foreach (array(
    'from_name',
    'from_address',
    'subject',
  ) as $field) {
    $option = $node->webform['email_' . $field . '_option'];
    if ($option == 'default') {
      $node->webform['email_' . $field] = 'default';
    }
    else {
      $node->webform['email_' . $field] = $node->webform['email_' . $field . '_' . $option];
    }
    unset($node->webform['email_' . $field . '_option']);
    unset($node->webform['email_' . $field . '_component']);
    unset($node->webform['email_' . $field . '_custom']);
  }

  // Set the submit limit to -1 if set to unlimited.
  if ($node->webform['enforce_limit'] == 'no') {
    $node->webform['submit_limit'] = -1;
    $node->webform['submit_interval'] = -1;
  }
  unset($node->webform['enforce_limit']);

  // Save roles.
  $node->webform['roles'] = array_keys(array_filter($node->webform['roles']));
}