The gform_rule_source_value Gravity Forms PHP filter allows you to modify the source value of a conditional logic rule before it is compared with the target value.
Usage
add_filter('gform_rule_source_value', function($source_value, $rule, $form, $logic, $entry) { // Modify the rule return $source_value; }, 10, 5);
Parameters
- $source_value (int|string): The value of the rule’s configured field ID, entry meta, or custom property.
- $rule (Rule Object): The current rule object. See the Rule Properties section of the Conditional Logic Object article.
- $form (Form Object): The current form meta.
- $logic (Conditional Logic Object): All details required to evaluate an object’s conditional logic.
- $entry (Entry Object): The entry currently being processed, if available.
More information
See Gravity Forms Docs: gform_rule_source_value
Examples
Change field value for a specific form and field
add_filter('gform_rule_source_value', function($source_value, $rule, $form, $logic, $entry) { // Changing the field value when evaluating conditional logic with source field id 3, and form id 1. if ($form['id'] == '1' && $rule['fieldId'] == '3') { $source_value = 'my custom field value'; } return $source_value; }, 10, 5);
Multiply the source value by 2
add_filter('gform_rule_source_value', function($source_value, $rule, $form, $logic, $entry) { // Multiply the source value by 2 $source_value *= 2; return $source_value; }, 10, 5);
Convert source value to uppercase
add_filter('gform_rule_source_value', function($source_value, $rule, $form, $logic, $entry) { // Convert the source value to uppercase $source_value = strtoupper($source_value); return $source_value; }, 10, 5);
Apply a custom function to the source value
function custom_function($value) { // Your custom function implementation here return $value; } add_filter('gform_rule_source_value', function($source_value, $rule, $form, $logic, $entry) { // Apply custom function to the source value $source_value = custom_function($source_value); return $source_value; }, 10, 5);
Append a custom string to the source value
add_filter('gform_rule_source_value', function($source_value, $rule, $form, $logic, $entry) { // Append a custom string to the source value $source_value .= ' - custom string'; return $source_value; }, 10, 5);