DescriptionUsageJavaScript VersionParametersExampleSource CodePHP VersionParametersExampleSource Code
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.
12345gform.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.
12345add_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
Parameters
isMatch boolean
Does the target field』s value match with the rule value?
formId integer
The ID of the form in use.
rule Javascript Object
The 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.
12345678gform.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;});
Source Code
This filter is located in js/conditional_logic.js
PHP Version
Parameters
$is_match boolean
Does the target field』s value match with the rule value?
$field_value string
The field value to use with the comparison.
$target_value string
The value from the conditional logic rule to use with the comparison.
$operation string
The conditional logic rule operator.
$source_field Field Object
The field object for the source of the field value.
$rule array
The 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.
1234567add_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 );
Source Code
This filter is located in RGFormsModel::is_value_match() in forms_model.php