function webform_email_edit_form_submit in Webform 7.3
Same name and namespace in other branches
- 6.3 includes/webform.emails.inc \webform_email_edit_form_submit()
- 7.4 includes/webform.emails.inc \webform_email_edit_form_submit()
Submit handler for webform_email_edit_form().
File
- includes/
webform.emails.inc, line 404 - Provides interface and database handling for e-mail settings of a webform.
Code
function webform_email_edit_form_submit($form, &$form_state) {
// Ensure a webform record exists.
$node = $form_state['values']['node'];
webform_ensure_record($node);
// Merge the e-mail, name, address, and subject options into single values.
$email = array(
'eid' => $form_state['values']['eid'],
'nid' => $node->nid,
);
foreach (array(
'email',
'from_name',
'from_address',
'subject',
) as $field) {
$option = $form_state['values'][$field . '_option'];
if ($option == 'default') {
$email[$field] = 'default';
}
else {
$email[$field] = $form_state['values'][$field . '_' . $option];
}
}
// Ensure templates are unaffected by differences in line breaks.
$form_state['values']['template'] = str_replace(array(
"\r",
"\n",
), array(
'',
"\n",
), $form_state['values']['template']);
$form_state['values']['templates']['default'] = str_replace(array(
"\r",
"\n",
), array(
'',
"\n",
), $form_state['values']['templates']['default']);
// Set the template value.
// TODO: Support reuse of templates.
if (strcmp(trim($form_state['values']['templates']['default']), trim($form_state['values']['template'])) == 0) {
$email['template'] = 'default';
}
else {
$email['template'] = $form_state['values']['template'];
}
// Save the attachment and HTML options provided by MIME mail.
$email['html'] = empty($form_state['values']['html']) ? 0 : 1;
$email['attachments'] = empty($form_state['values']['attachments']) ? 0 : 1;
// Save the list of included components.
// We actually maintain an *exclusion* list, so any new components will
// default to being included in the %email_values token until unchecked.
$included = array_keys(array_filter((array) $form_state['values']['components']));
$excluded = array_diff(array_keys($node->webform['components']), $included);
$email['excluded_components'] = $excluded;
if (empty($form_state['values']['eid'])) {
drupal_set_message(t('Email settings added.'));
$form_state['values']['eid'] = webform_email_insert($email);
}
else {
drupal_set_message(t('Email settings updated.'));
webform_email_update($email);
}
// Clear the entity cache if Entity Cache module is installed.
if (module_exists('entitycache')) {
entity_get_controller('node')
->resetCache(array(
$node->nid,
));
}
$form_state['redirect'] = array(
'node/' . $node->nid . '/webform/emails',
);
}