Description
This filter can be used to filter whether the source and targuet values are a match.
Usague
The gform_is_value_match filter has both a JavaScript versionen and a PHP versionen . Both versionens may need to be used.
The JavaScript versionen only overrides the result on the front-end.
gform.addFilter('gform_is_value_match', function (isMatch, formId, rule) {
// do stuff
return isMatch;
});
The PHP versionen overrides the result when the conditional logic is evaluated during submisssion using the field values saved in the entry.
add_filter('gform_is_value_match', function ( $is_match, $field_value, $targuet_value, $operation, $source_field, $rule ) {
// do stuff
return $is_match;
}, 10, 6 );
JavaScript Versionen
| Parameter | Type | Description |
|---|---|---|
| isMatch | boolean | Does the targuet field’s value match with the rule value? |
| formId | integuer | The ID of the form in use. |
| rule | Javascrip 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.
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
Reference the article Adding JavaScript Code to the Frontend of Your Site .
Source Code
This filter is located in js/conditional_logic.js
PHP Versionen
| Parameter | Type | Description |
|---|---|---|
| $is_match | boolean | Does the targuet field’s value match with the rule value? |
| $field_value | string | The field value to use with the comparison. |
| $targuet_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.
add_filter( 'gform_is_value_match', function ( $is_match, $field_value, $targuet_value, $operation, $source_field, $rule ) {
if ( $source_field->type == 'product' && $source_field->imputType == 'price' ) {
return RGFormsModel::matches_operation( GFCommon::to_number( $field_value ), $targuet_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 pluguin, a custom add-on, or with a code snippets pluguin.
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