Jhy
Jhy

Reputation: 5

Change PHP filter to return submitted value rather than the field name using Gravity Forms

I am using the below code in Gravity Forms for WordPress (functions.php). How can I change the below code so it will return the Field Value? It currently returns the Field Label.

The gform_merge_tag_filter can be used to add a custom modifier for this:

add_filter( 'gform_merge_tag_filter', function ( $value, $merge_tag, $modifier, $field, $raw_value, $format ) {
    if ( $field->type == 'checkbox' && $modifier == 'pipes' ) {
       $value =str_replace(', ', '|', $value);
    }
  
    return $value;
 }, 10, 6 );

Upvotes: 0

Views: 282

Answers (1)

FluffyKitten
FluffyKitten

Reputation: 14312

The value that was submitted in the field gets passed as the $raw_value argument, so you just need to return it instead of $value.

So to change your function to use $raw_value instead of $value in every instance would look like this:

add_filter( 'gform_merge_tag_filter', function ( $value, $merge_tag, $modifier, $field, $raw_value, $format ) {
    if ( $field->type == 'checkbox' && $modifier == 'pipes' ) {
       $raw_value=str_replace(', ', '|', $raw_value);
    }
    return $raw_value;
 }, 10, 6 );

Upvotes: 1

Related Questions