Call gf_after_submission using value from specific field

I have an existing form with an API that is triggered using gf_after_submission for this form only. After some last minute requirements changes I now need the API to trigger only if a specific field on the form has a specific value.

This late in the game Im hoping to avoid having to create separate forms - one for each potential value - and direct users there based on their answer to the trigger question.

My original proposal was to create a Lead-In type question and based on that answer direct them to the appropriate form and call the gf_after_submission_x where “X” would be the correct form. But that means having the same form and the same API code three times?

Example:
Users who are between the ages of 20 and 25 will require a different API call than users who are between the ages of 26 and 30…and users who are between the ages of 31 and 40 will require a third API call.

Erm…

add_action( 'gform_after_submission_45', 'after_submit_45', 10, 2 );
function after_submit_45( $entry, $form ) {
      if( $form['id'] == 45 ){

        $field_1 = rgar( $entry, '1' );

        if ($field_1 > 20 && $field_1 < 25) {
          //STUFF HAPPPENS
        }
    }
 }
1 Like