Skip to content

Commit 78f1873

Browse files
committed
Fixes format of entry value if needed
1 parent a0cede0 commit 78f1873

File tree

6 files changed

+54
-8
lines changed

6 files changed

+54
-8
lines changed

includes/class-ajax.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -528,7 +528,7 @@ public function get_entry_detail() {
528528
$has_empty = false;
529529
$answers = [];
530530
$respondentPoints = isset( $form_settings['total_points'] ) ? floatval( $form_settings['total_points'] ) : 0;
531-
531+
$fields_formatted = array();
532532
foreach ( $fields as $key => $field ) {
533533
if ( $form_settings['quiz_form'] == 'yes' ) {
534534
$selectedAnswers = isset( $field['selected_answers'] ) ? $field['selected_answers'] : '';
@@ -539,7 +539,6 @@ public function get_entry_detail() {
539539

540540
if ( $template == 'radio_field' || $template == 'dropdown_field' ) {
541541
$answers[$field['name']] = true;
542-
543542
if ( empty( $givenAnswer ) ) {
544543
$answers[$field['name']] = false;
545544
$respondentPoints -= $fieldPoints;
@@ -576,11 +575,13 @@ public function get_entry_detail() {
576575
} elseif ( empty( $field['value'] ) ) {
577576
$has_empty = true;
578577
break;
578+
} else {
579+
$field = WeForms_Form_Entry_Manager::format_entry_details( $field );
580+
array_push( $fields_formatted, $field );
579581
}
580582
}
581-
582583
$response = [
583-
'form_fields' => $fields,
584+
'form_fields' => $fields_formatted,
584585
'form_settings' => $form_settings,
585586
'meta_data' => $metadata,
586587
'payment_data' => $payment,
@@ -589,6 +590,7 @@ public function get_entry_detail() {
589590
'answers' => $answers,
590591
];
591592

593+
592594
wp_send_json_success( $response );
593595
}
594596

includes/class-form-entry-manager.php

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,48 @@ public function all() {
5151
public function get( $entry_id ) {
5252
return new WeForms_Form_Entry( $entry_id, $this->form );
5353
}
54+
55+
/**
56+
* Format Entry Values.
57+
*
58+
* @static
59+
* @param array $field
60+
*
61+
* @return array $field
62+
*/
63+
public static function format_entry_details( $field ) {
64+
switch ( $field['template'] ) {
65+
66+
case 'radio_field':
67+
$value = array_search( $field['value'], $field['options'] );
68+
$field['value'] = esc_html( 'Option: ' . $field['value'] . ' - ' . 'Value: ' . $value );
69+
70+
break;
71+
72+
case 'checkbox_field':
73+
$field_formatted = array();
74+
foreach ( $field['value'] as $option ) {
75+
$value = array_search( $option, $field['options'] );
76+
$field_formatted[] = esc_html( 'Option: ' . $option . ' - ' . 'Value: ' . $value );
77+
}
78+
$field['value'] = array_replace( $field['value'], $field_formatted );
79+
80+
break;
81+
82+
case 'multiple_select':
83+
$field_formatted = array();
84+
foreach ( $field['value'] as $option ) {
85+
$value = array_search( $option, $field['options'] );
86+
$field_formatted[] = esc_html( 'Option: ' . $option . ' - ' . 'Value: ' . $value );
87+
}
88+
$field['value'] = array_replace( $field['value'], $field_formatted );
89+
90+
break;
91+
92+
default:
93+
// Do nothing if value format does not need to be changed.
94+
break;
95+
}
96+
return $field;
97+
}
5498
}

includes/fields/class-field-checkbox.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ public function prepare_entry( $field, $args = [] ) {
118118
$new_val = [];
119119

120120
foreach ( $entry_value as $option_key ) {
121-
$new_val[] = isset( $field['options'][$option_key] ) ? $field['options'][$option_key] . ' , ' . $option_key : $option_key;
121+
$new_val[] = isset( $field['options'][$option_key] ) ? $field['options'][$option_key] : $option_key;
122122
}
123123

124124
$entry_value = implode( WeForms::$field_separator, $new_val );

includes/fields/class-field-multidropdown.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public function prepare_entry( $field, $args = [] ) {
103103
$new_val = [];
104104

105105
foreach ( $entry_value as $option_key ) {
106-
$new_val[] = isset( $field['options'][$option_key] ) ? $field['options'][$option_key] . ' , ' . $option_key : $option_key;
106+
$new_val[] = isset( $field['options'][$option_key] ) ? $field['options'][$option_key] : $option_key;
107107
}
108108

109109
$entry_value = implode( WeForms::$field_separator, $new_val );

includes/fields/class-field-radio.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,6 @@ public function prepare_entry( $field, $args = [] ) {
120120
$args = ! empty( $args ) ? $args : weforms_clean( $_POST );
121121
$val = $args[$field['name']];
122122

123-
return isset( $field['options'][$val] ) ? $field['options'][$val] . ' , ' . $val : $val;
123+
return isset( $field['options'][$val] ) ? $field['options'][$val] : $val;
124124
}
125125
}

includes/functions.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ function weforms_get_entry_payment( $entry_id ) {
177177
$query = 'SELECT transaction_id FROM ' . $wpdb->prefix . 'weforms_payments' .
178178
' WHERE entry_id = ' . $entry_id;
179179
$payment = $wpdb->get_row( $query, $entry_id );
180-
180+
181181
return $payment;
182182
}
183183

0 commit comments

Comments
 (0)