Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 3 additions & 26 deletions experimental/gpdtc-recalc.php
Original file line number Diff line number Diff line change
@@ -1,29 +1,6 @@
<?php
/**
* Gravity Perks // Date Time Calculator // Recalculate Field Value on View
* https://gravitywiz.com/documentation/gravity-forms-date-time-calculator/
*
* Recalculate a calculated field's value every time it's viewed.
*
* Works great with Date Time Calculator's [:age modifier][1].
*
* [1]: https://gravitywiz.com/documentation/gravity-forms-date-time-calculator/#calculating-age
* We're no longer using the experimental folder for experimental snippets. 🚧
* You can now find the snippet here:
* https://github.com/gravitywiz/snippet-library/blob/master/gp-date-time-calculator/gpdtc-recalc.php
*/
add_action( 'wp_loaded', function() {

$form_id = 123; // Change this to the form's ID
$field_id = 4; // Change this to the Calculation field's ID.

$values = array();

add_filter( sprintf( 'gform_get_input_value_%s', $form_id ), function( $value, $entry, $field, $input_id ) use ( $field_id, &$values ) {
if ( $field['id'] !== $field_id ) {
$values[ $field['id'] ] = $value;
return $value;
}
$form = GFAPI::get_form( $entry['form_id'] );
$_entry = $entry + $values;
return GFCommon::calculate( $field, $form, $_entry );
}, 10, 4 );

} );
Loading