foreach ($formContent as $formPages) { $pageContent = json_decode($formPages->page_content); $submissionDetail = ''; $submissionEdit = ''; foreach ($pageContent as $fields) { $key = $fields->id; if (isset($fields->type) && $fields->type != 'static-content' && $fields->type != 'google-maps') { $submissionDetail .= '<dt>' . $fields->options->label . ':</dt><dd id="' . $key . '">'; $submissionEdit .= '<div class="control-group "> <label class="control-label">' . $fields->options->label . ':</label> <div class="controls">'; $contentField = ''; $contentFieldEdit = ''; $contentFieldDetail = ''; if (isset($submission->{$key})) { $contentField = WR_Contactform_Helpers_Contactform::get_data_field($fields->type, $submission, $key, $this->id, false); $contentFieldEdit = $contentField; if ($fields->type == 'email') { $contentFieldDetail = !empty($contentField) ? '<a href="mailto:' . $contentField . '">' . $contentField . '</a>' : 'N/A'; } else { $contentFieldDetail = $contentField; } } //if ( isset( $fields->type ) && $fields->type == 'likert' ) if (isset($fields->type) && ($fields->type == 'likert' || $fields->type == 'email' || $fields->type == 'file-upload')) { $submissionDetail .= $contentFieldDetail ? str_replace('\\n', '<br/>', trim($contentFieldDetail)) : 'N/A'; } else { $submissionDetail .= $contentFieldDetail ? str_replace('\\n', '<br/>', htmlentities(html_entity_decode(trim($contentFieldDetail)))) : 'N/A'; } if (isset($fields->type) && ($fields->type == 'checkboxes' || $fields->type == 'list' || $fields->type == 'paragraph-text')) { if ($fields->type == 'checkboxes' || $fields->type == 'list') {
/** * 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; } }
/** * Render a custom column in the listing page. * * @param array $column Column name. * @param array $post_id Post id. * @param bool $return Return String * * @return void */ public static function render_submissions_column($column, $post_id, $return = false, $formID = '') { $html = ''; global $wpdb; if (in_array($column, array('ip', 'browser', 'os'))) { if (empty($formID)) { $formID = !empty($_SESSION['wr-contactform']['form_id']) ? $_SESSION['wr-contactform']['form_id'] : ''; } if (!empty($formID) && is_numeric($formID)) { $submissionData = $wpdb->get_results($wpdb->prepare("SELECT * FROM {$wpdb->prefix}wr_contactform_submission_data WHERE form_id = %d AND field_id = 0 AND submission_id=%d AND field_type=%s ORDER BY submission_data_id ASC", (int) $formID, (int) $post_id, $column)); $value = !empty($submissionData[0]->submission_data_value) ? $submissionData[0]->submission_data_value : 'N/A'; if ($return) { return $value; } else { _e($value); } } } else { if ($column == 'total_submissions') { $meta = get_post_meta((int) $post_id); if (!empty($meta['form_id'][0])) { $form_id = (int) $meta['form_id'][0]; } else { $form_id = (int) $post_id; } $where = ''; $total = $wpdb->get_var("SELECT COUNT(*) FROM {$wpdb->posts} WHERE (post_status = 'publish' OR post_status = 'trash' OR post_status = 'draft' OR post_status = 'pending') AND (post_content = '" . (int) $form_id . "' AND post_type = 'wr_cfsb_post_type' ) " . $where); return '<a href="edit.php?post_status=all&post_type=wr_cfsb_post_type&action=-1&m=0&paged=1&mode=list&action2=-1&wr_contactform_form_id=' . $form_id . '">' . $total . '</a>'; } else { if ($column == 'form_short_code') { $meta = get_post_meta((int) $post_id); if (!empty($meta['form_id'][0])) { $form_id = (int) $meta['form_id'][0]; } else { $form_id = (int) $post_id; } return '[wr_contactform id=' . $form_id . ']'; } else { if ($column == 'date_created') { $title = '<strong><a title="Edit Submission" href="post.php?post=' . (int) $post_id . '&action=edit" class="row-title">' . get_the_date('m/d/Y H:i:s', (int) $post_id) . '</a></strong>'; return $title; } else { $column = str_replace('_', '', $column); if (empty($formID)) { $formID = !empty($_SESSION['wr-contactform']['form_id']) ? $_SESSION['wr-contactform']['form_id'] : ''; } if (!empty($formID) && is_numeric($formID) && !empty($column) && is_numeric($column)) { $submissionData = $wpdb->get_results($wpdb->prepare("SELECT * FROM {$wpdb->prefix}wr_contactform_submission_data WHERE form_id = %d AND field_id = %d AND submission_id=%d ORDER BY submission_data_id ASC", (int) $formID, (int) $column, (int) $post_id)); if (!empty($submissionData[0])) { $getData = WR_Contactform_Helpers_Contactform::get_data_field($submissionData[0]->field_type, $submissionData[0], '', $formID, true, true, 'list'); if ($return) { return $getData; } else { _e($getData); } } } } } } } }