/** * Save form submission * * @param Array $post Post form * @param int $postID Post ID * * @return Messages */ public function save($post, $postID) { global $wpdb; $return = new stdClass(); $submissionsData = array(); $validationForm = array(); $requiredField = array(); $postFormId = isset($post['form_id']) ? $post['form_id'] : ''; $dataForms = get_post_meta((int) $postID); $formSettings = !empty($dataForms['form_settings'][0]) ? json_decode($dataForms['form_settings'][0]) : ''; if (empty($formSettings)) { return; } $dataForms['form_id'] = (int) $postFormId; $dataContentEmail = ''; $fileAttach = ''; $nameFileByIndentifier = ''; $global_captcha_setting = get_option('wr_contactform_global_captcha_setting', 2); if ($global_captcha_setting != 0) { if (!empty($formSettings->form_captcha) && $formSettings->form_captcha == 1 && isset($_POST['recaptcha_challenge_field'])) { include_once WR_CONTACTFORM_PATH . 'libraries/3rd-party/recaptchalib.php'; $recaptchaChallenge = isset($_POST['recaptcha_challenge_field']) ? $_POST['recaptcha_challenge_field'] : ''; $recaptchaResponse = isset($_POST['recaptcha_response_field']) ? $_POST['recaptcha_response_field'] : ''; $resp = recaptcha_check_answer(WR_CONTACTFORM_CAPTCHA_PRIVATEKEY, $_SERVER['REMOTE_ADDR'], $recaptchaChallenge, $recaptchaResponse); if (!$resp->is_valid) { $return->error['captcha'] = __('Incorrect captcha text!', WR_CONTACTFORM_TEXTDOMAIN); return $return; } } else { if (!empty($formSettings->form_captcha) && $formSettings->form_captcha == 2 || $global_captcha_setting == 1) { if (!empty($_POST['form_name']) && !empty($_POST['captcha'])) { $sCaptcha = $_SESSION['securimage_code_value'][$_POST['form_name']] ? $_SESSION['securimage_code_value'][$_POST['form_name']] : ''; if (strtolower($sCaptcha) != strtolower($_POST['captcha'])) { $return->error['captcha_2'] = __('Incorrect captcha text!', WR_CONTACTFORM_TEXTDOMAIN); return $return; } } else { $return->error['captcha_2'] = __('Incorrect captcha text!', WR_CONTACTFORM_TEXTDOMAIN); return $return; } } } } $columsSubmission = $wpdb->get_results($wpdb->prepare("SELECT * FROM {$wpdb->prefix}wr_contactform_fields WHERE form_id = %d ORDER BY field_ordering ASC", (int) $postFormId)); $fieldClear = array(); if (isset($dataForms->form_type) && $dataForms->form_type == 1) { $dataPages = $wpdb->get_results($wpdb->prepare("SELECT * FROM {$wpdb->prefix}wr_contactform_form_pages WHERE form_id = %d ORDER BY page_id ASC", (int) $dataForms['form_id'])); foreach ($dataPages as $index => $page) { if ($index > 0) { $contentPage = isset($page->page_content) ? json_decode($page->page_content) : ''; foreach ($contentPage as $item) { $fieldClear[] = $item->id; } } } } $postAction = !empty($dataForms['form_post_action'][0]) ? $dataForms['form_post_action'][0] : ''; $postActionData = !empty($dataForms['form_post_action_data'][0]) ? unserialize($dataForms['form_post_action_data'][0]) : ''; self::get_action_form($postAction, $postActionData, $return); $fieldEmail = array(); $ip = getenv('REMOTE_ADDR'); $browser = new Browser(); $submissionsData[] = array('form_id' => $postFormId, 'submission_data_value' => $browser->getPlatform(), 'field_type' => 'os'); $submissionsData[] = array('form_id' => $postFormId, 'submission_data_value' => $browser->getBrowser(), 'field_type' => 'browser'); $submissionsData[] = array('form_id' => $postFormId, 'submission_data_value' => $ip, 'field_type' => 'ip'); foreach ($columsSubmission as $colum) { if (!in_array($colum->field_id, $fieldClear)) { $fieldName = ''; $fieldName = $colum->field_id; $fieldSettings = isset($colum->field_settings) ? json_decode($colum->field_settings) : ''; $value = ''; $fieldEmail[$colum->field_id] = $colum->field_identifier; $formTypeNotSave = array('static-content', 'google-maps'); $formTypeNotSave = apply_filters('wr_contactform_filter_form_type_not_save', $formTypeNotSave); if (isset($colum->field_type) && !in_array($colum->field_type, $formTypeNotSave)) { if (in_array($colum->field_type, array('single-line-text', 'paragraph-text', 'country'))) { $postFieldName = isset($post[$fieldName]) ? $post[$fieldName] : ''; $postName = stripslashes($postFieldName); $value = $postName ? $postName : ''; } elseif ($colum->field_type == 'choices' || $colum->field_type == 'dropdown') { $value = self::field_others($post, $fieldSettings, $fieldName); } elseif (in_array($colum->field_type, array('checkboxes', 'list'))) { $value = self::field_json($post, $colum->field_type, $fieldName); } else { $getValue = ''; $getValue = apply_filters('wr_contactform_get_value_type_' . str_replace('-', '_', $colum->field_type), $post, $fieldName, $colum, $fieldSettings); if (is_array($getValue)) { foreach ($getValue as $idField => $text) { $validationForm[$idField] = $text; } } else { if (is_string($getValue)) { $value = $getValue; } } } // htmlentities to form inputs if (in_array($colum->field_type, array('single-line-text', 'paragraph-text', 'address', 'name', 'password'))) { $value = htmlentities($value); } $submissionsData[] = array('form_id' => $postFormId, 'field_id' => $colum->field_id, 'submission_data_value' => $value, 'field_type' => $colum->field_type); $keyField = $colum->field_id; $submissions = new stdClass(); $submissions->{$keyField} = $value; if (isset($colum->field_type)) { $nameFileByIndentifier[$colum->field_identifier] = $colum->field_title; $contentField = WR_Contactform_Helpers_Contactform::get_data_field($colum->field_type, $submissions, $colum->field_id, $postFormId, false, false, 'email'); if ($colum->field_type == 'file-upload') { $fileAttach[$colum->field_identifier] = WR_Contactform_Helpers_Contactform::get_data_field($colum->field_type, $submissions, $colum->field_id, $postFormId, false, false, 'fileAttach'); } /* Create Filter get file attachment*/ $fileAttach = apply_filters('wr_contactform_frontend_file_attachment_email', $fileAttach, $colum, $submissions, $postFormId); $dataContentEmail[$colum->field_identifier] = $contentField ? str_replace('\\n', '<br/>', trim($contentField)) : '<span>N/A</span>'; $requiredField[$colum->field_identifier] = $fieldSettings->options->required; } if (!empty($fieldSettings->options->noDuplicates) && (int) $fieldSettings->options->noDuplicates == 1) { WR_CF_Gadget_Contactform_Frontend::check_duplicates($post, $fieldName, $colum->field_title, $validationForm); } if (isset($fieldSettings->options->limitation) && (int) $fieldSettings->options->limitation == 1 && !empty($post[$fieldName])) { if ($fieldSettings->options->limitMin <= $fieldSettings->options->limitMax && $fieldSettings->options->limitMax > 0) { self::check_limit_char($post, $fieldSettings, $fieldName, $colum->field_title, $validationForm); } } if (isset($fieldSettings->options->requiredConfirm) && (int) $fieldSettings->options->requiredConfirm == 1) { $postData = isset($post[$fieldName]) ? $post[$fieldName] : ''; $postDataConfirm = isset($post[$fieldName . '_confirm']) ? $post[$fieldName . '_confirm'] : ''; if (isset($fieldSettings->options->required) && (int) $fieldSettings->options->required == 1 && $postData != $postDataConfirm) { $error = __('Both %s addresses must be the same.', WR_CONTACTFORM_TEXTDOMAIN); $validationForm[$fieldName] = str_replace('%s', $colum->field_title, $error); } else { if (!empty($postData) && !empty($postDataConfirm) && $postData != $postDataConfirm) { $error = __('Both %s addresses must be the same.', WR_CONTACTFORM_TEXTDOMAIN); $validationForm[$fieldName] = str_replace('%s', $colum->field_title, $error); } } } if (isset($fieldSettings->options->required) && (int) $fieldSettings->options->required == 1 && (int) $fieldSettings->options->hideField != 1) { $checkValidation = array(); $checkValidation = apply_filters('wr_contactform_filter_required_type_' . str_replace('-', '_', $colum->field_type), $checkValidation, $post, $fieldName, $colum, $fieldSettings); if (!empty($checkValidation)) { if (is_array($checkValidation)) { $validationForm = array_merge($validationForm, $checkValidation); } } else { if (isset($post[$fieldName]) && $post[$fieldName] == '') { $validationForm[$fieldName] = __('This field can not be empty, please enter required information.', WR_CONTACTFORM_TEXTDOMAIN); } } } do_action('wr_contactform_frontend_action_save_form', $validationForm, $submissions, $postFormId, $fieldSettings, $post, $fieldName, $colum); $validationForm = apply_filters('wr_contactform_frontend_validation_save_form', $validationForm, $colum, $submissions, $postFormId, $fieldSettings, $post, $fieldName); } else { $formTypeNotSendEmail = array(); $formTypeNotSendEmail[] = 'google-maps'; $formTypeNotSendEmail[] = 'file-upload'; $formTypeNotSendEmail = apply_filters('wr_contactform_filter_form_type_not_send_email', $formTypeNotSendEmail); if (isset($colum->field_type) && !in_array($colum->field_type, $formTypeNotSendEmail)) { $nameFileByIndentifier[$colum->field_identifier] = $colum->field_title; $dataContentEmail[$colum->field_identifier] = $fieldSettings->options->value; } } } } if (!$validationForm) { self::_save($dataForms, (int) $postID, $return, $post, $submissionsData, $dataContentEmail, $nameFileByIndentifier, $requiredField, $fileAttach); return $return; } else { $return->error = $validationForm; return $return; } }
/** * get value file field likert */ function filter_wr_contactform_get_value_type_likert($post, $fieldIdentifier, $colum, $fieldSettings) { $value = WR_CF_Gadget_Contactform_Frontend::field_json($post, $colum->field_type, $fieldIdentifier); return $value; }