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(); ?>
" . esc_html(($map_data[$key]['mf_input_label'] != '') ? $map_data[$key]['mf_input_label'] : $key) . " | "; 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 " | " . esc_html($result) . " | "; }else{ echo "" . esc_html( $option_text ) . " | "; } } else if(isset($value['widgetType']) && $value['widgetType'] == 'mf-text-editor') { echo "" . wp_kses_post($form_data[$key]) . " | "; }else{ $output = isset($form_data[$key]) ? (is_array($form_data[$key]) ? implode(', ', $form_data[$key]) : $form_data[$key]) : ''; echo "" . esc_html($output) . " | "; } } if (isset($value['widgetType']) && $value['widgetType'] == 'mf-mobile') { $output = isset($form_data[$key]) && !empty($form_data[$key]) ? '+' . esc_html($form_data[$key]) : ''; echo "" . $output . " | "; } 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 "" . esc_html($result) . " | "; } } else { $output = isset($form_data[$key]) ? (is_array($form_data[$key]) ? implode(', ', $form_data[$key]) : $form_data[$key]) : ''; echo "" . esc_html($output) . " | "; } } 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 "" . esc_html($option_text) . " | "; } else { echo "" . esc_html($option_value) . " | "; } } if (isset($value['widgetType']) && $value['widgetType'] == 'mf-signature') { echo ""; } if (isset($value['widgetType']) && $value['widgetType'] == 'mf-textarea') { echo " | " . wp_kses( isset($form_data[$key]) ? nl2br( $form_data[$key] ) : '', [ 'br' => [] ]) . " | "; } if (isset($value['widgetType']) && $value['widgetType'] == 'mf-simple-repeater') { echo "";
$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 " | ";
}
/**
* Credit Card form data entries
*/
if (isset($value['widgetType']) && $value['widgetType'] == 'mf-credit-card') {
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 | "; } } if (isset($value['widgetType']) && ($value['widgetType'] == 'mf-like-dislike')) { $like_dislike = (isset($form_data[$key]) ? $form_data[$key] : ''); echo ""; echo (($like_dislike == '1') ? "" : ""); echo (($like_dislike == '0') ? "" : ""); echo " | "; } echo "
" . esc_html(($map_data[$key]['mf_input_label'] != '') ? $map_data[$key]['mf_input_label'] : $key) . " | "; echo "|||||
"; if (!in_array($value['widgetType'], ['mf-file-upload', 'mf-textarea', 'mf-simple-repeater', 'mf-signature', 'mf-credit-card'])) { echo " | " . esc_html((array_key_exists($key, $form_data) ? ((is_array($form_data[$key])) ? implode(', ', $form_data[$key]) : $form_data[$key]) : ' ')) . " | "; } if (isset($value['widgetType']) && $value['widgetType'] == 'mf-textarea') { echo "" . esc_html(isset($form_data[$key]) ? $form_data[$key] : '') . " | ";
}
if (isset($value['widgetType']) && $value['widgetType'] == 'mf-signature') {
echo ""; } if (isset($value['widgetType']) && $value['widgetType'] == 'mf-simple-repeater') { echo " | ";
$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 " | ";
}
/**
* Credit Card form data entries
*/
if (isset($value['widgetType']) && $value['widgetType'] == 'mf-credit-card') {
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 "
" . esc_html(($map_data[$key]['mf_input_label'] != '') ? $map_data[$key]['mf_input_label'] : $key) . " | "; echo "|||||
"; echo " | "; foreach($file as $value) { echo "".esc_html__('Download', 'metform')." "; } echo " | "; echo "