function processForms() { if (isset($_POST['ccf_customhtml']) || isset($_POST['customcontactforms_submit'])) { // BEGIN define common language vars $lang = array(); $lang['field_blank'] = __('You left this field blank: ', 'custom-contact-forms'); $lang['form_page'] = __('Form Displayed on Page: ', 'custom-contact-forms'); $lang['sender_ip'] = __('Sender IP: ', 'custom-contact-forms'); // END define common language vars } if (isset($_POST['ccf_customhtml'])) { $admin_options = parent::getAdminOptions(); $fixed_customhtml_fields = array('required_fields', 'success_message', 'thank_you_page', 'destination_email', 'ccf_customhtml'); $req_fields = $this->requiredFieldsArrayFromList($_POST['required_fields']); $req_fields = array_map('trim', $req_fields); $body = ''; foreach ($_POST as $key => $value) { if (!in_array($key, $fixed_customhtml_fields)) { if (in_array($key, $req_fields) && !empty($value)) { unset($req_fields[array_search($key, $req_fields)]); } $body .= ucwords(str_replace('_', ' ', htmlspecialchars($key))) . ': ' . htmlspecialchars($value) . "<br /><br />\n"; $data_array[$key] = $value; } } foreach ($req_fields as $err) { $this->setFormError($err, $lang['field_blank'] . '"' . $err . '"'); } $errors = $this->getAllFormErrors(); if (empty($errors)) { ccf_utils::load_module('export/custom-contact-forms-user-data.php'); $data_object = new CustomContactFormsUserData(array('data_array' => $data_array, 'form_page' => $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'], 'form_id' => 0, 'data_time' => time())); parent::insertUserData($data_object); $body .= "<br />\n" . htmlspecialchars($lang['form_page']) . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'] . "<br />\n" . $lang['sender_ip'] . $_SERVER['REMOTE_ADDR'] . "<br />\n"; if ($admin_options['email_form_submissions'] == 1) { if (!class_exists('PHPMailer')) { require_once ABSPATH . "wp-includes/class-phpmailer.php"; } $mail = new PHPMailer(); $mail->MailerDebug = false; if ($admin_options['mail_function'] == 'smtp') { $mail->IsSMTP(); $mail->Host = $admin_options['smtp_host']; if ($admin_options['smtp_authentication'] == 1) { $mail->SMTPAuth = true; $mail->Username = $admin_options['smtp_username']; $mail->Password = $admin_options['smtp_password']; $mail->Port = $admin_options['smtp_port']; } else { $mail->SMTPAuth = false; } } $mail->From = $admin_options['default_from_email']; $mail->FromName = 'Custom Contact Forms'; $dest_email_array = $this->getDestinationEmailArray($_POST['destination_email']); if (empty($dest_email_array)) { $mail->AddAddress($admin_options['default_to_email']); } else { foreach ($dest_email_array as $em) { $mail->AddAddress($em); } } $mail->Subject = $admin_options['default_form_subject']; $mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; $mail->MsgHTML(stripslashes($body)); $mail->Send(); } if ($_POST['thank_you_page']) { ccf_utils::redirect($_POST['thank_you_page']); } $this->current_thank_you_message = !empty($_POST['success_message']) ? $_POST['success_message'] : $admin_options['form_success_message']; $this->current_form = 0; add_action('wp_footer', array(&$this, 'insertFormSuccessCode'), 1); } unset($_POST); } elseif (isset($_POST['customcontactforms_submit'])) { ccf_utils::startSession(); $this->error_return = $_POST['form_page']; $admin_options = parent::getAdminOptions(); $fields = parent::getAttachedFieldsArray($_POST['fid']); $post_time = time(); $form = parent::selectForm($_POST['fid']); $checks = array(); $reply = isset($_POST['fixedEmail']) ? $_POST['fixedEmail'] : NULL; $fixed_subject = isset($_POST['emailSubject']) ? $_POST['emailSubject'] : NULL; $cap_name = 'ccf_captcha_' . $_POST['fid']; foreach ($fields as $field_id) { $field = parent::selectField($field_id, ''); if ($field->field_slug == 'ishuman') { if (!isset($_POST['ishuman']) || isset($_POST['ishuman']) && $_POST['ishuman'] != 1) { if (empty($field->field_error)) { $this->setFormError('ishuman', __('Only humans can use this form.', 'custom-contact-forms')); } else { $this->setFormError('ishuman', $field->field_error); } } } elseif ($field->field_slug == 'captcha') { if ($_POST['captcha'] != $_SESSION[$cap_name]) { if (empty($field->field_error)) { $this->setFormError('captcha', __('You copied the number from the captcha field incorrectly.', 'custom-contact-forms')); } else { $this->setFormError('captcha', $field->field_error); } } } elseif ($field->field_slug == 'recaptcha') { require_once CCF_BASE_PATH . 'modules/recaptcha/recaptchalib.php'; $resp = recaptcha_check_answer($admin_options['recaptcha_private_key'], $_SERVER['REMOTE_ADDR'], $_POST['recaptcha_challenge_field'], $_POST['recaptcha_response_field']); if (!$resp->is_valid) { if (empty($field->field_error)) { $this->setFormError('recaptcha', __('You copied the text from the captcha field incorrectly.', 'custom-contact-forms')); } else { $this->setFormError('recaptcha', $field->field_error); } } } elseif ($field->field_slug == 'fixedEmail' && $field->field_required == 1 && !empty($_POST['fixedEmail'])) { if (!$this->validEmail($_POST['fixedEmail'])) { if (empty($field->field_error)) { $this->setFormError('fixedEmail', __('The email address you provided is not valid.', 'custom-contact-forms')); } else { $this->setFormError('fixedEmail', $field->field_error); } } } elseif ($field->field_slug == 'fixedWebsite' && $field->field_required == 1 && !empty($_POST['fixedWebsite'])) { if (!$this->validWebsite($_POST['fixedWebsite'])) { if (empty($field->field_error)) { $this->setFormError('fixedWebsite', __('The website address you provided is not valid.', 'custom-contact-forms')); } else { $this->setFormError('fixedWebsite', $field->field_error); } } } else { $field_error_label = empty($field->field_label) ? $field->field_slug : $field->field_label; if ($field->field_required == 1 && $field->field_type != 'File' && !empty($_POST[$field->field_slug])) { if ($field->field_type == 'Dropdown' || $field->field_type == 'Radio' || $field->field_type == 'Checkbox') { // TODO: find better way to check for a dead state if ($_POST[$field->field_slug] == CCF_DEAD_STATE_VALUE) { if (empty($field->field_error)) { $this->setFormError($field->field_slug, $lang['field_blank'] . '"' . $field_error_label . '"'); } else { $this->setFormError($field->field_slug, $field->field_error); } } } } elseif ($field->field_required == 1 && $field->field_type != 'File' && empty($_POST[$field->field_slug])) { if (empty($field->field_error)) { $this->setFormError($field->field_slug, $lang['field_blank'] . '"' . $field_error_label . '"'); } else { $this->setFormError($field->field_slug, $field->field_error); } } else { // file field required and not found if ($field->field_required == 1 && $field->field_type == 'File' && empty($_FILES[$field->field_slug]['name'])) { if (empty($field->field_error)) { $this->setFormError($field->field_slug, $lang['field_blank'] . '"' . $field_error_label . '"'); } else { $this->setFormError($field->field_slug, $field->field_error); } } elseif ($field->field_type == 'File' && !empty($_FILES[$field->field_slug]['name'])) { $upload_result = $this->processFileUpload($field, $post_time); foreach ($upload_result as $err) { $this->setFormError($field->field_slug, $err); } } } } if ($field->field_type == 'Checkbox') { $checks[] = $field->field_slug; } } $body = ''; $data_array = array(); foreach ($_POST as $key => $value) { $_SESSION['ccf_fields'][$key] = $value; //if (is_array($value)) $value = implode(', ', $value); $val2 = is_array($value) ? implode(', ', $value) : $value; $field = parent::selectField('', $key); if (!array_key_exists($key, $GLOBALS['ccf_fixed_fields']) || $key == 'fixedEmail' || $key == 'usaStates' || $key == 'fixedWebsite' || $key == 'emailSubject' || $key == 'allCountries') { $mail_field_label = empty($field->field_label) ? $field->field_slug : $field->field_label; $body .= htmlspecialchars($mail_field_label) . ' - ' . htmlspecialchars($val2) . "<br />\n"; $data_array[$key] = $value; } if (in_array($key, $checks)) { $checks_key = array_search($key, $checks); unset($checks[$checks_key]); } } foreach ($this->form_uploads as $name => $upload) { $file_url = preg_replace('/^.*(\\/custom-contact-forms\\/.*)$/i', plugins_url() . '$1', $upload); if (!array_key_exists($name, $GLOBALS['ccf_fixed_fields'])) { $data_array[$name] = '[file link="' . $file_url . '"]' . basename($upload) . '[/file]'; } } foreach ($checks as $check_key) { $field = parent::selectField('', $check_key); $lang['not_checked'] = __('Not Checked', 'custom-contact-forms'); $data_array[$check_key] = $lang['not_checked']; $body .= ucwords(str_replace('_', ' ', htmlspecialchars($field->field_label))) . ' - ' . $lang['not_checked'] . "<br />\n"; } $errors = $this->getAllFormErrors(); if (empty($errors)) { ccf_utils::load_module('export/custom-contact-forms-user-data.php'); unset($_SESSION['ccf_captcha_' . $_POST['fid']]); unset($_SESSION['ccf_fields']); $data_object = new CustomContactFormsUserData(array('data_array' => $data_array, 'form_page' => $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'], 'form_id' => $form->id, 'data_time' => $post_time)); parent::insertUserData($data_object); if ($admin_options['email_form_submissions'] == '1') { $body .= "<br />\n" . htmlspecialchars($lang['form_page']) . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'] . "<br />\n" . $lang['sender_ip'] . $_SERVER['REMOTE_ADDR'] . "<br />\n"; if (!class_exists('PHPMailer')) { require_once ABSPATH . "wp-includes/class-phpmailer.php"; } $mail = new PHPMailer(false); $mail->MailerDebug = false; if ($admin_options['mail_function'] == 'smtp') { $mail->IsSMTP(); $mail->Host = $admin_options['smtp_host']; if ($admin_options['smtp_authentication'] == 1) { $mail->SMTPAuth = true; $mail->Username = $admin_options['smtp_username']; $mail->Password = $admin_options['smtp_password']; $mail->Port = $admin_options['smtp_port']; } else { $mail->SMTPAuth = false; } } $dest_email_array = $this->getDestinationEmailArray($form->form_email); $from_name = empty($admin_options['default_from_name']) ? __('Custom Contact Forms', 'custom-contact-forms') : $admin_options['default_from_name']; if (!empty($form->form_email_name)) { $from_name = $form->form_email_name; } if (empty($dest_email_array)) { $mail->AddAddress($admin_options['default_to_email']); } else { foreach ($dest_email_array as $em) { $mail->AddAddress($em); } } foreach ($this->form_uploads as $file_upload) { $mail->AddAttachment($file_upload); } if ($reply != NULL && $this->validEmail($reply)) { $mail->From = $reply; } else { $mail->From = $admin_options['default_from_email']; } $mail->FromName = $from_name; $mail->Subject = !empty($form->form_email_subject) ? $form->form_email_subject : $admin_options['default_form_subject']; if ($fixed_subject != NULL) { $mail->Subject = $fixed_subject; } $mail->AltBody = __("To view the message, please use an HTML compatible email viewer.", 'custom-contact-forms'); $mail->CharSet = 'utf-8'; $mail->MsgHTML(stripslashes($body)); $mail->Send(); } if (!empty($form->form_thank_you_page)) { ccf_utils::redirect(str_replace('&', '&', $form->form_thank_you_page)); } $this->current_form = $form->id; add_action('wp_footer', array(&$this, 'insertFormSuccessCode'), 1); } unset($_POST); $_POST = array(); } }