get_fields($form_id); return static::$form_data = json_decode(json_encode($map_data), true); } protected static function criteriaMet($conditional_value, $conditional_operator, $conditional_field_value) { switch ($conditional_operator) { case '<': return $conditional_value < $conditional_field_value; case '<=': return $conditional_value <= $conditional_field_value; case '>': return $conditional_value > $conditional_field_value; case '>=': return $conditional_value >= $conditional_field_value; case '==': return $conditional_value == $conditional_field_value; case '!=': return $conditional_value != $conditional_field_value; case 'empty': return empty($conditional_value); case 'not-empty': return !empty($conditional_value); default: return false; } } public static function format_form_data($form_id, $form_data) { $map_data = static::get_form_data($form_id); $form_settings = \MetForm\Core\Forms\Action::instance()->get_all_data($form_id); ob_start(); ?>
$value) { if (in_array($value['widgetType'], ['mf-simple-captcha', 'mf-recaptcha', 'mf-file-upload'])) { continue; } $conditions = isset($map_data[$key]["mf_conditional_logic_form_list"]) ? $map_data[$key]["mf_conditional_logic_form_list"] : []; $no_of_condition = count($conditions); $checking_result = array(); $condition_match_criteria = !empty($map_data[$key]["mf_conditional_logic_form_and_or_operators"]) ? $map_data[$key]["mf_conditional_logic_form_and_or_operators"] : ''; list($map_data, $form_data, $checking_result) = self::condition_criteria_match($map_data, $key, $conditions, $form_data, $checking_result); if ($no_of_condition > 1 && $condition_match_criteria == "or") { if (!in_array(true, $checking_result)) { continue; } } else { if (in_array(false, $checking_result)) { continue; } } echo ""; echo ""; echo ""; $entriy_row_correct_class = ''; if(isset($form_settings['form_type']) && $form_settings['form_type'] === 'quiz-form' && isset($form_data['wrong-answer']) && isset($form_data['right-answer'])){ $wrong_answers = explode(",", $form_data['wrong-answer']); $right_answers = explode(",", $form_data['right-answer']); // Find thefield if it exists in the right answers array if(in_array($map_data[$key]['mf_input_name'], $right_answers)){ $entriy_row_correct_class = 'mf_correct_result'; } elseif( in_array($map_data[$key]['mf_input_name'], $wrong_answers) ){ $entriy_row_correct_class = 'mf_wrong_result'; } } echo sprintf("", esc_attr($entriy_row_correct_class)); echo ""; if (!in_array($value['widgetType'], ['mf-file-upload', 'mf-textarea', 'mf-simple-repeater', 'mf-signature', 'mf-like-dislike', 'mf-credit-card','mf-image-select','mf-checkbox','mf-mobile'])) { $label = isset($map_data[$key]['mf_input_label']) ? $map_data[$key]['mf_input_label'] : ''; if ($label && isset($map_data[$key]['mf_input_list']) && is_array($map_data[$key]['mf_input_list']) && isset($form_settings['mf_field_name_show'] ) && $form_settings['mf_field_name_show'] == 1) { $selected_values = isset($form_data[$key]) ? explode(',', $form_data[$key]) : array(); $values = array(); foreach ($map_data[$key]['mf_input_list'] as $item) { // Check if 'label' key exists in the item if ( isset($item['label']) && in_array($item['value'], $selected_values) ) { $values[$item['label']] = $item['label'] . ' - ' . $item['value']; } if ( isset($item['mf_input_option_text']) && isset($item['mf_input_option_value']) && $item['mf_input_option_value'] == $form_data[$key] ) { $option_text = $item['mf_input_option_text'] .' - '. $item['mf_input_option_value'] ; } } $result = implode(', ', $values); if(!empty($result)){ echo ""; }else{ echo ""; } } else if(isset($value['widgetType']) && $value['widgetType'] == 'mf-text-editor') { echo ""; }else{ $output = isset($form_data[$key]) ? (is_array($form_data[$key]) ? implode(', ', $form_data[$key]) : $form_data[$key]) : ''; echo ""; } } if (isset($value['widgetType']) && $value['widgetType'] == 'mf-mobile') { $output = isset($form_data[$key]) && !empty($form_data[$key]) ? '+' . esc_html($form_data[$key]) : ''; echo ""; } if (isset($value['widgetType']) && $value['widgetType'] == 'mf-checkbox') { $label = isset($map_data[$key]['mf_input_label']) ? $map_data[$key]['mf_input_label'] : ''; if ($label && isset($map_data[$key]['mf_input_list']) && is_array($map_data[$key]['mf_input_list']) && isset($form_settings['mf_field_name_show']) && $form_settings['mf_field_name_show'] == 1) { $selected_values = isset($form_data[$key]) ? explode(',', $form_data[$key]) : array(); $values = array(); foreach ($map_data[$key]['mf_input_list'] as $item) { if (isset($item['mf_input_option_text']) && in_array($item['mf_input_option_value'], $selected_values)) { $values[$item['mf_input_option_text']] = $item['mf_input_option_text'] . ' - ' . $item['mf_input_option_value']; } } $result = implode(', ', $values); if (!empty($result)) { echo ""; } } else { $output = isset($form_data[$key]) ? (is_array($form_data[$key]) ? implode(', ', $form_data[$key]) : $form_data[$key]) : ''; echo ""; } } if (isset($value['widgetType']) && $value['widgetType'] == 'mf-image-select') { $selected_value = isset($form_data[$key]) ? $form_data[$key] : ''; $option_text = ''; $option_value = ''; foreach ($map_data[$key]['mf_input_list'] as $item) { if (isset($item['mf_input_option_value']) && $item['mf_input_option_value'] == $selected_value ) { if (isset($item['mf_image_select_title']) && $item['mf_image_select_title'] !== '') { // If mf_image_select_title is not empty, use it in the option text. $option_text = $item['mf_image_select_title'] . ' - ' . $item['mf_input_option_value']; } else { // If mf_image_select_title is empty, use mf_input_option_value. $option_text = $item['mf_input_option_value']; } $option_value = $item['mf_input_option_value']; } } if (isset($form_settings['mf_field_name_show']) && $form_settings['mf_field_name_show'] == 1) { echo ""; } else { echo ""; } } if (isset($value['widgetType']) && $value['widgetType'] == 'mf-signature') { echo ""; } if (isset($value['widgetType']) && $value['widgetType'] == 'mf-textarea') { echo ""; } if (isset($value['widgetType']) && $value['widgetType'] == 'mf-simple-repeater') { echo ""; } /** * Credit Card form data entries */ if (isset($value['widgetType']) && $value['widgetType'] == 'mf-credit-card') { echo ""; } } if (isset($value['widgetType']) && ($value['widgetType'] == 'mf-like-dislike')) { $like_dislike = (isset($form_data[$key]) ? $form_data[$key] : ''); echo ""; } echo ""; } ?>
" . esc_html(($map_data[$key]['mf_input_label'] != '') ? $map_data[$key]['mf_input_label'] : $key) . "
 " . esc_html($result) . "" . esc_html( $option_text ) . "" . wp_kses_post($form_data[$key]) . "" . esc_html($output) . "" . $output . "" . esc_html($result) . "" . esc_html($output) . "" . esc_html($option_text) . "" . esc_html($option_value) . "" . wp_kses( isset($form_data[$key]) ? nl2br( $form_data[$key] ) : '', [ 'br' => [] ]) . ""; $repeater_data = ((array_key_exists($key, $form_data)) ? $form_data[$key] : []); $count_index = 0; // number of repeater input field counter $previous_level = null; foreach ($repeater_data as $k => $v) { $repeater_level = null; if ((isset($map_data[$key]["mf_input_repeater"][$count_index]["mf_input_repeater_label"]))) { $repeater_level = $map_data[$key]["mf_input_repeater"][$count_index]["mf_input_repeater_label"]; } if ((isset($map_data[$key]["mf_input_repeater"][$count_index - 1]["mf_input_repeater_label"]))) { $previous_level = $map_data[$key]["mf_input_repeater"][$count_index - 1]["mf_input_repeater_label"]; } if ($repeater_level == null && $previous_level != null) { $repeater_level = $previous_level; } echo "" . esc_html(($repeater_level != null) ? $repeater_level : $k) . ": "; if ($repeater_level && isset($map_data[$key]["mf_input_repeater"][$count_index]["mf_input_repeater_option"]) && isset($form_settings['mf_field_name_show']) && $form_settings['mf_field_name_show'] == 1) { $options = explode("\n", $map_data[$key]["mf_input_repeater"][$count_index]["mf_input_repeater_option"]); $optionOutput = []; $selected_options = explode(',', $v); foreach ($options as $option) { list($optionName, $optionValue) = explode('|', $option); if (in_array($optionValue, $selected_options)) { $optionOutput[] = "$optionName - $optionValue"; } } echo wp_kses_post("" . implode(", ", $optionOutput) . ""); } else { echo wp_kses_post("" . esc_html($v) . ""); } echo "
"; $count_index++; if ($count_index == count($map_data[$key]["mf_input_repeater"])) { $count_index = 0; echo "
"; } } echo "
". esc_html__('Number:', 'metform') ." " . esc_html(isset($form_data[$key]) ? $form_data[$key] : '') . "
"; if (isset($form_data[$key . '--type'])) { $type = $form_data[$key . '--type']; $type = ($type === "amex") ? 'Amerian Express' : $type; echo "".esc_html__('Type:', 'metform')." " . esc_html(ucfirst($type)) . " Card
"; echo (($like_dislike == '1') ? "" : ""); echo (($like_dislike == '0') ? "" : ""); echo "
$value) { if (in_array($value['widgetType'], ['mf-simple-captcha', 'mf-recaptcha', 'mf-file-upload', 'mf-button'])) { continue; } $conditions = isset($map_data[$key]["mf_conditional_logic_form_list"]) ? $map_data[$key]["mf_conditional_logic_form_list"] : []; $no_of_condition = count($conditions); $checking_result = array(); $condition_match_criteria = !empty($map_data[$key]["mf_conditional_logic_form_and_or_operators"]) ? $map_data[$key]["mf_conditional_logic_form_and_or_operators"] : ''; list($map_data, $form_data, $checking_result) = self::condition_criteria_match($map_data, $key, $conditions, $form_data, $checking_result); if ($no_of_condition > 1 && $condition_match_criteria == "or") { if (!in_array(true, $checking_result)) { continue; } } else { if (in_array(false, $checking_result)) { continue; } } echo ""; echo ""; echo ""; echo ""; echo ""; if (!in_array($value['widgetType'], ['mf-file-upload', 'mf-textarea', 'mf-simple-repeater', 'mf-signature', 'mf-credit-card'])) { echo ""; } if (isset($value['widgetType']) && $value['widgetType'] == 'mf-textarea') { echo ""; } if (isset($value['widgetType']) && $value['widgetType'] == 'mf-signature') { echo ""; } if (isset($value['widgetType']) && $value['widgetType'] == 'mf-simple-repeater') { echo ""; } /** * Credit Card form data entries */ if (isset($value['widgetType']) && $value['widgetType'] == 'mf-credit-card') { echo ""; } } echo ""; } if (!empty($file_info)) { foreach ($file_info as $key => $file) { echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; } } ?>
" . esc_html(($map_data[$key]['mf_input_label'] != '') ? $map_data[$key]['mf_input_label'] : $key) . "
 " . esc_html((array_key_exists($key, $form_data) ? ((is_array($form_data[$key])) ? implode(', ', $form_data[$key]) : $form_data[$key]) : ' ')) . "
" . esc_html(isset($form_data[$key]) ? $form_data[$key] : '') . "
"; $repeater_data = ((array_key_exists($key, $form_data)) ? $form_data[$key] : []); // counter and variables $count_index = 0 ; // number of repeter input field counter $previous_level = null; foreach ($repeater_data as $k => $v) { $repeter_level = null; if((isset($map_data[$key]["mf_input_repeater"][$count_index]["mf_input_repeater_label"]))){ $repeter_level = $map_data[$key]["mf_input_repeater"][$count_index]["mf_input_repeater_label"]; } if((isset($map_data[$key]["mf_input_repeater"][$count_index-1]["mf_input_repeater_label"]))){ // store previous level $previous_level = $map_data[$key]["mf_input_repeater"][$count_index-1]["mf_input_repeater_label"]; } if($repeter_level == null && $previous_level != null){ // repeter level empty then set previous level to repeter level $repeter_level = $previous_level; } echo "" . esc_html( ($repeter_level != null)? $repeter_level : $k) . ": "; echo "" . esc_html($v) . ""; echo "
"; $count_index ++; if($count_index == count($map_data[$key]["mf_input_repeater"])){ // repeter input field count exceed count_index repeter has repetition set count_index 0 $count_index = 0; echo "
"; } } echo "
". esc_html__('Number:', 'metform') ." " . esc_html(isset($form_data[$key]) ? $form_data[$key] : '') . "
"; if (isset($form_data[$key . '--type'])) { $type = $form_data[$key . '--type']; $type = ($type === "amex") ? 'Amerian Express' : $type; echo "".esc_html__('Type:', 'metform')." " . esc_html(ucfirst($type)) . " Card
" . esc_html(($map_data[$key]['mf_input_label'] != '') ? $map_data[$key]['mf_input_label'] : $key) . "
 "; foreach($file as $value) { echo "".esc_html__('Download', 'metform')." "; } echo "
$condition) { $conditional_field_name = !empty($condition["mf_conditional_logic_form_if"]) ? $condition["mf_conditional_logic_form_if"] : ''; $conditional_operator = !empty($condition["mf_conditional_logic_form_comparison_operators"]) ? $condition["mf_conditional_logic_form_comparison_operators"] : 'not-empty'; // operator value not-empty hole backend theke data ase na tai not-empty default vabe dewa hoise.. // if condition logic change after submission previous entries condition also change. $conditional_field_value = !empty($condition["mf_conditional_logic_form_value"]) ? $condition["mf_conditional_logic_form_value"] : ''; $conditional_value_data = !empty($form_data[$conditional_field_name]) ? $form_data[$conditional_field_name] : ''; $condition_value_array = explode(",",$conditional_value_data); $condition_value_index = array_search($conditional_field_value, $condition_value_array); $conditional_value = isset($condition_value_array[$condition_value_index])? $condition_value_array[$condition_value_index] : ""; $criteria_match = static::criteriaMet($conditional_value, $conditional_operator, $conditional_field_value); array_push($checking_result, $criteria_match); } } return array($map_data, $form_data, $checking_result); } }