Using exponents in Gravity Forms calculations Using exponents in Gravity Forms calculations wordpress wordpress

Using exponents in Gravity Forms calculations


The javascript snippet you used above will change what the user sees, but it will not change the saved form data, per say. You instead need to add a PHP filter to the functions.php file of your theme.

add_filter( 'gform_calculation_result', function ( $result, $formula, $field, $form, $entry ) {    if ( $form['id'] == 1 && $field['id'] == 10 ) {        $base = 1 + (float) rgar( $entry, '8' ); // '8' should be field ID of Calc        $exponent = (float) rgar( $entry, '1' ); // '1' should be field ID of Number of monthly payments        $result   = pow( $base, $exponent );    }    return $result;}, 10, 5 );

One warning: this will not change anything that the user "sees" when filling out the form. It will only change the final calculation after the user hits the submit button.

It would also be cleaner to do all of your calculations in a filter like this rather than using hidden form data.