gform_is_value_match

Description

This filter can be used to filter whether the source and target values are a match.

Usage

The gform_is_value_match filter has both a JavaScript version and a PHP version. Both versions may need to be used.

The JavaScript version only overrides the result on the front-end.

gform.addFilter('gform_is_value_match', function (isMatch, formId, rule) {
    // do stuff

    return isMatch;
});

The PHP version overrides the result when the conditional logic is evaluated during submission using the field values saved in the entry.

add_filter('gform_is_value_match', function ( $is_match, $field_value, $target_value, $operation, $source_field, $rule ) {
    // do stuff

    return $is_match;
}, 10, 6 );

JavaScript Version

ParameterTypeDescription
isMatchbooleanDoes the target field’s value match with the rule value?
formIdintegerThe ID of the form in use.
ruleJavascrip ObjectThe current rule object. e.g.
{"fieldId":3,"operator":"<","value":"5"}

Example

This example shows how you can perform the value and rule comparison for a custom field type which may use a custom method for storing its value.

gform.addFilter('gform_is_value_match', function (isMatch, formId, rule) {
    var couponField = jQuery('#field_' + formId + '_' + rule.fieldId).find('#gf_coupon_codes_' + formId);
    if (couponField.length) {
        return gf_matches_operation(couponField.val(), rule.value, rule.operator);
    }

    return isMatch;
});

Placement

Your code snippet can be placed in an HTML field on your form or in a theme custom JavaScript file.

See also the JavaScript/jQuery section in this article: Where Do I Put This Code?

Source Code

This filter is located in js/conditional_logic.js

PHP Version

ParameterTypeDescription
$is_matchbooleanDoes the target field’s value match with the rule value?
$field_valuestringThe field value to use with the comparison.
$target_valuestringThe value from the conditional logic rule to use with the comparison.
$operationstringThe conditional logic rule operator.
$source_fieldField ObjectThe field object for the source of the field value.
$rulearrayThe current rule object.

Example

This example shows how you can perform the value and rule comparison for a field type which may store its value in a custom format.

add_filter( 'gform_is_value_match', function ( $is_match, $field_value, $target_value, $operation, $source_field, $rule ) {
    if ( $source_field->type == 'product' && $source_field->inputType == 'price' ) {
        return RGFormsModel::matches_operation( GFCommon::to_number( $field_value ), $target_value, $operation );
    }

    return $is_match;
}, 10, 6 );

Placement

This code can be used in the functions.php file of the active theme, a custom functions plugin, a custom add-on, or with a code snippets plugin.

See also the PHP section in this article: Where Do I Put This Code?

Source Code

This filter is located in RGFormsModel::is_value_match() in forms_model.php