Skip to content

Commit 6580c4e

Browse files
sbassahsaifsultanc
authored andcommitted
gw-set-range-by-field-values.php: Added "Evolved" message.
1 parent aa92f1f commit 6580c4e

File tree

1 file changed

+3
-25
lines changed

1 file changed

+3
-25
lines changed
Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,6 @@
11
<?php
22
/**
3-
* Gravity Wiz // Gravity Forms // Populate Range by Another Field
4-
* https://gravitywiz.com/
5-
*
6-
* Set a field's minimum and maximum range by the values of other fields. Currently, this will only work with default
7-
* values. If the value changes after the form has been rendered, it will still generate a validation error but the
8-
* range message that displays below the input will not update automatically.
3+
* This snippet has evolved! 🦄
4+
* Find the new version of this snippet here:
5+
* https://gravitywiz.com/snippet-library/gw-dynamic-range/
96
*/
10-
// Update "123" to your form ID.
11-
add_filter( 'gform_pre_render_123', 'gw_set_range', 10, 3 );
12-
add_filter( 'gform_pre_process_123', 'gw_set_range', 10, 3 );
13-
function gw_set_range( $form, $ajax, $field_values ) {
14-
15-
foreach ( $form['fields'] as &$field ) {
16-
// Update "4" to the ID of the field that should have its range modified.
17-
if ( $field->id == 4 ) {
18-
// Update "5" to the ID of the field whose value should be used for the minimum range.
19-
$min_field = GFAPI::get_field( $form, 5 );
20-
$field->rangeMin = GFFormsModel::get_field_value( $min_field, $field_values );
21-
// Update "6" to the ID of the field whose value should be used for the maximum range.
22-
$max_field = GFAPI::get_field( $form, 6 );
23-
$field->rangeMax = GFFormsModel::get_field_value( $max_field, $field_values );
24-
}
25-
}
26-
27-
return $form;
28-
}

0 commit comments

Comments
 (0)