Skip to content

Commit 4cb0beb

Browse files
committed
fixes #142
1 parent 2a592fd commit 4cb0beb

File tree

2 files changed

+45
-24
lines changed

2 files changed

+45
-24
lines changed

includes/class-form-entry-manager.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,12 @@ public static function format_entry_value( $field ) {
8989

9090
break;
9191

92+
case 'dropdown_field':
93+
$value = array_search( $field['value'], $field['options'] );
94+
$field['value'] = esc_html( 'Option: ' . $field['value'] . ' - ' . 'Value: ' . $value );
95+
96+
break;
97+
9298
default:
9399
// Do nothing if value format does not need to be changed.
94100
break;

includes/class-notification.php

Lines changed: 39 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -463,33 +463,48 @@ public function get_merge_value( $tag ) {
463463
}
464464

465465
/**
466-
* Parse out the custom fields with entry meta values
466+
* Parse out the custom fields with options or values. Since the options are what is stored, options may need to be
467+
* used to find the value from the field settings.
467468
*
468469
* @param string $text
470+
* @param int $entry_id
469471
*
470472
* @return string
471473
*/
472-
public static function replace_field_tags( $text, $entry_id ) {
473-
$pattern = '/{field:(\w*)}/';
474-
475-
preg_match_all( $pattern, $text, $matches );
476-
477-
// bail out if nothing found to be replaced
478-
if ( !$matches ) {
479-
return $text;
480-
}
481-
482-
foreach ( $matches[1] as $index => $meta_key ) {
483-
$meta_value = weforms_get_entry_meta( $entry_id, $meta_key, true );
484-
485-
if ( is_array( $meta_value ) ) {
486-
$meta_value = implode( WeForms::$field_separator, $meta_value );
487-
}
488-
489-
$text = str_replace( $matches[0][$index], $meta_value, $text );
474+
public function replace_field_tags( $text, $entry_id ) {
475+
$pattern_field = '/{field:(\w*)}/';
476+
$pattern_value = '/{value:(\w*)}/';
477+
switch ( $text ) {
478+
case '':
479+
return $text;
480+
break;
481+
case ( preg_match( $pattern_field, $text, $matches ) ? true : false ):
482+
$meta_key = $matches[1];
483+
$meta_value = weforms_get_entry_meta( $entry_id, $meta_key, true );
484+
if ( is_array( $meta_value ) ) {
485+
$meta_value = implode( WeForms::$field_separator, $meta_value );
486+
}
487+
$text = str_replace( $matches[0], $meta_value, $text );
488+
return $text;
489+
break;
490+
case ( preg_match( $pattern_value, $text, $matches ) ? true : false ):
491+
$meta_key = $matches[1];
492+
$form = weforms()->form->get( $this->args['form_id'] );
493+
$form_field = $form->get_field_values();
494+
$form_field_values = $form_field[ $meta_key ]['options'];
495+
$meta_value = weforms_get_entry_meta( $entry_id, $meta_key, true );
496+
// The modified value is the value of the field in the form since it is not stored.
497+
$modified_value = array_search( $meta_value, $form_field_values );
498+
if ( is_array( $modified_value ) ) {
499+
$modified_value = implode( WeForms::$field_separator, $modified_value );
500+
}
501+
$text = str_replace( $matches[0], $modified_value, $text );
502+
return $text;
503+
break;
504+
default:
505+
return $text;
506+
break;
490507
}
491-
492-
return $text;
493508
}
494509

495510
/**
@@ -604,8 +619,8 @@ public function replace_tags( $text = '' ) {
604619
$merge_values = array_values( $this->merge_tags );
605620

606621
$text = str_replace( $merge_keys, $merge_values, $text );
607-
$text = static::replace_field_tags( $text, $this->args['entry_id'] );
608-
$text = static::replace_file_tags( $text, $this->args['entry_id'] );
622+
$text = $this->replace_field_tags( $text, $this->args['entry_id'] );
623+
$text = $this->replace_file_tags( $text, $this->args['entry_id'] );
609624

610625
return $text;
611626
}
@@ -662,7 +677,7 @@ public function replace_all_fields( $text = '' ) {
662677
$table .= '—';
663678
}
664679
} elseif ( in_array( $value['type'], array( 'google_map' ) ) ) {
665-
$table .= $field_value['address'];
680+
$table .= $field_value['address'];
666681
} else {
667682
$table .= $field_value;
668683
}

0 commit comments

Comments
 (0)