GFAPI::count_entries - update - and validate before save

Maybe I haven’t described the problem that I would like to solve quite clearly.

In the form I have a field - calculation. AFTER sending the form, I would like this field to be populated with the count value from gf_api.

And then this value is validated. If the value is greater than 5, the form should not be left saved.

I am using this code to calculate count.

add_filter( 'gform_calculation_result', function ( $result, $formula, $field, $form, $entry ) {       
    if ( $form['id'] == 1 && $field['id'] == 51 ) {

        $sum_hold_per_user =  GFAPI::count_entries(1, [
            'field_filters' => [
                ['key' => 22, 'value' => $entry[2]], // email field
                ['key' => 25, 'operator' => 'is', 'value' => 'hold'], // status field
            ],
        ]);

         $result = $ilosc_wygranych_do_tej_pory;	
		 		
    }

    return $result;
}, 10, 5 );

The problem is that when I use gform_calculation_result, the field is completed with the correct count.

But unfortunately the validation does not work on it.

© 2008 - 2019. Gravity Forms is a project by Rocketgenius Inc.