Skip to content

Commit 0c23a04

Browse files
authored
gpdtc-recalc.php: Updated header and removed GPDTC dependency.
1 parent 971d44f commit 0c23a04

File tree

1 file changed

+24
-15
lines changed

1 file changed

+24
-15
lines changed

experimental/gpdtc-recalc.php

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,29 @@
11
<?php
22
/**
3-
* Re-calculate a GPDTC calculated field dynamically every time it's viewed.
3+
* Gravity Perks // Date Time Calculator // Recalculate Field Value on View
4+
* https://gravitywiz.com/documentation/gravity-forms-date-time-calculator/
5+
*
6+
* Recalculate a calculated field's value every time it's viewed.
7+
*
8+
* Works great with Date Time Calculator's [:age modifier][1].
9+
*
10+
* [1]: https://gravitywiz.com/documentation/gravity-forms-date-time-calculator/#calculating-age
411
*/
512
add_action( 'wp_loaded', function() {
6-
$form_id = 13; // Change this to the form's ID
7-
$field_id = 132; // Change this to the Age's field ID
8-
if ( class_exists( 'GP_Date_Time_Calculator' ) ) {
9-
$values = array();
10-
add_filter( sprintf( 'gform_get_input_value_%s', $form_id ), function( $value, $entry, $field, $input_id ) use ( $field_id, &$values ) {
11-
if ( $field['id'] !== $field_id ) {
12-
$values[ $field['id'] ] = $value;
13-
return $value;
14-
}
15-
$form = GFAPI::get_form( $entry['form_id'] );
16-
$lead = $entry + $values;
17-
return GFCommon::calculate( $field, $form, $lead );
18-
}, 10, 4 );
19-
}
13+
14+
$form_id = 123; // Change this to the form's ID
15+
$field_id = 4; // Change this to the Calculation field's ID.
16+
17+
$values = array();
18+
19+
add_filter( sprintf( 'gform_get_input_value_%s', $form_id ), function( $value, $entry, $field, $input_id ) use ( $field_id, &$values ) {
20+
if ( $field['id'] !== $field_id ) {
21+
$values[ $field['id'] ] = $value;
22+
return $value;
23+
}
24+
$form = GFAPI::get_form( $entry['form_id'] );
25+
$_entry = $entry + $values;
26+
return GFCommon::calculate( $field, $form, $_entry );
27+
}, 10, 4 );
28+
2029
} );

0 commit comments

Comments
 (0)