function webform_client_form_submit in Webform 5
Same name and namespace in other branches
- 5.2 webform.module \webform_client_form_submit()
- 6.3 webform.module \webform_client_form_submit()
- 6.2 webform.module \webform_client_form_submit()
- 7.4 webform.module \webform_client_form_submit()
- 7.3 webform.module \webform_client_form_submit()
File
- ./webform.module, line 1461
Code
function webform_client_form_submit($form_id, $form_values) {
global $user, $base_url;
include_once drupal_get_path('module', 'webform') . "/webform.inc";
$node = node_load(array(
'nid' => $form_values['details']['nid'],
));
$session_key = 'webform_form_' . $node->nid;
if ($form_values['op'] != t('Submit')) {
if (is_array($_SESSION[$session_key])) {
foreach ($_SESSION[$session_key] as $key => $val) {
$_POST['submitted'][$key] = $val;
}
}
if (is_array($form_values['submitted'])) {
foreach ($form_values['submitted'] as $key => $val) {
$_SESSION[$session_key][$key] = $val;
}
}
return;
}
if (is_array($_SESSION[$session_key])) {
foreach ($_SESSION[$session_key] as $key => $val) {
$form_values['submitted'][$key] = $val;
}
unset($_SESSION[$session_key]);
}
_webform_client_form_submit_process($node, $form_values['submitted']);
$form_values['submitted_tree'] = $form_values['submitted'];
_webform_client_form_submit_flatten($node, $form_values['submitted'], $form_values['submitted']);
if (trim($node->additional_submit)) {
eval("?>" . $node->additional_submit);
}
if (!$form_values['details']['sid']) {
$sid = _webform_save_submission($node, $form_values['submitted']);
}
else {
$sid = _webform_update_submission($node, $form_values['details']['sid'], $form_values['submitted']);
}
if (isset($node->email) && !$form_values['details']['sid']) {
$node->email = strip_tags($node->email);
if (!empty($node->email)) {
$message = theme("webform_create_mailmessage_{$node->nid}", $form_values, $node, $sid);
if (!$message) {
$message = theme("webform_create_mailmessage", $form_values, $node, $sid);
}
$email_from_name = variable_get('webform_default_from_name', variable_get('site_name', ''));
$email_from_address = variable_get('webform_default_from_email', variable_get('site_mail', ini_get('sendmail_from')));
$email_subject_string = variable_get('webform_default_subject', t('Form submission from: ')) . ' ' . $node->title;
$headers = array();
if ($node->email_from_name == 'none') {
$email_from_name = '';
}
if ($node->email_from_address == 'none') {
$email_from_address = '';
}
if ($node->email_subject == 'none') {
$email_subject_string = '';
}
if (is_array($node->webformcomponents) && !empty($node->webformcomponents)) {
foreach ($node->webformcomponents as $cid => $component) {
$type = $component['type'];
if ($type == 'email' || $type == 'hidden' || $type == 'select') {
if ($component['name'] == $node->email_from_address) {
$email_from_address = check_plain($form_values['submitted'][$cid]);
}
}
if ($type == 'textfield' || $type == 'hidden' || $type == 'select') {
if ($component['name'] == $node->email_from_name) {
$email_from_name = check_plain($form_values['submitted'][$cid]);
}
if ($component['name'] == $node->email_subject) {
$email_subject_string = check_plain($form_values['submitted'][$cid]);
}
}
if ($type == 'email' && $component['extra']['carboncopy'] == 'Y') {
$headers['Cc'] = check_plain($form_values['submitted'][$cid]);
}
}
}
if (strlen($email_from_name) > 0) {
$email_from_string = mime_header_encode($email_from_name) . ' <' . $email_from_address . '>';
}
else {
$email_from_string = $email_from_address;
}
if (_webform_submission_spam_check($node->email, $email_subject_string, $message, $email_from_string, $headers)) {
watchdog('webform', t('Possible spam attempt from ') . $_SERVER['REMOTE_ADDR'] . "<br />\n" . nl2br(htmlentities($message)), WATCHDOG_WARNING);
drupal_set_message(t("Illegal information. Data not submitted."), 'error');
return false;
}
$headers['X-Mailer'] = 'Drupal Webform (PHP/' . phpversion() . ')';
drupal_mail('webform-submission', $node->email, $email_subject_string, $message, $email_from_string, $headers);
if (variable_get('webform_debug', 0) >= 2) {
drupal_set_message("E-mail Headers: <pre>" . htmlentities(print_r($headers, true)) . "</pre>To: " . $node->email . "<br />From: " . htmlentities($email_from_string) . "<br />Subject: " . $email_subject_string . "<br />E-mail Body: <pre>" . $message . "</pre>");
}
}
}
if (variable_get('webform_debug', 0) >= 2) {
drupal_set_message('$form_values are: <pre>' . htmlentities(print_r($form_values, true)) . '</pre>');
drupal_set_message('$_SERVER is: <pre>' . htmlentities(print_r($_SERVER, true)) . '</pre>');
drupal_set_message('$_POST is: <pre>' . htmlentities(print_r($_POST, true)) . '</pre>');
}
if (variable_get('webform_debug', 0) >= 1) {
watchdog('webform', t('Submission posted to %title', array(
'%title' => $node->title,
)) . l(t('Results'), 'node/' . $node->nid, NULL, 'sid=' . $sid) . "<br />\n<pre>" . htmlentities(print_r($form_values, TRUE)) . "</pre>", WATCHDOG_NOTICE);
}
if (valid_url(trim($node->confirmation), true)) {
$redirect = trim($node->confirmation);
}
elseif (preg_match('/^internal:/', $node->confirmation) && $node->redirect_post) {
$path = preg_replace('/^internal:/', $base_url . '/', $node->confirmation);
$redirect = trim($path);
}
elseif (preg_match('/^internal:/', $node->confirmation)) {
$path = preg_replace('/^internal:/', '', $node->confirmation);
$redirect = array(
trim($path),
'sid=' . $sid,
);
}
else {
$redirect = array(
'node/' . $node->nid . '/done',
'sid=' . $sid,
);
}
return $redirect;
}