How to reliably extract individual sub-values (First, Last, Street Address, City, etc.) from Name and Address fields in gform_after_submission?

Hi everyone,

I’m sending Gravity Forms submission data via a custom webhook to Airtable using gform_after_submission.
Everything works perfectly for simple fields, but Name, Address, and other compound fields are not sending their individual parts (First & Last for Name; Street Address, City, State, ZIP for Address) — they are missing entirely on the Airtable side.

Here’s my current code (Form ID 41) that I believed should work — it loops through $field->inputs and tries to pull every possible label source:

add_action( 'gform_after_submission_41', 'savemyfurbaby_form41_to_airtable', 10, 2 );
function savemyfurbaby_form41_to_airtable( $entry, $form ) {

    // ... page restriction and webhook URL ...

    $payload = new stdClass();

    foreach ( $form['fields'] as $field ) {
        if ( $field->is_administrative || $field->visibility === 'hidden' ) continue;

        // COMPOUND FIELDS
        if ( ! empty( $field->inputs ) && is_array( $field->inputs ) ) {
            foreach ( $field->inputs as $input ) {
                if ( ! empty( $input['isHidden'] ) ) continue;

                $input_id = (string) $input['id'];
                $value    = rgar( $entry, $input_id );

                $label = '';
                if ( ! empty( $input['customLabel'] ) )      $label = $input['customLabel'];
                elseif ( ! empty( $input['label'] ) )        $label = $input['label'];
                elseif ( ! empty( $input['placeholder'] ) )  $label = $input['placeholder'];
                else $label = 'Field ' . $input_id;

                $label = trim( $label );
                $safe_label = str_replace( [ '"', '\\', ':' ], '', $label );

                $payload->$safe_label = (string) $value;
            }
            continue;
        }

        // REGULAR FIELDS
        $label = trim( GFCommon::get_label( $field ) );
        $value = rgar( $entry, (string) $field->id );
        // ... handle arrays, etc. ...
        $safe_label = str_replace( [ '"', '\\' ], '', $label );
        $payload->$safe_label = (string) ( $value ?? '' );
    }

    // ... meta fields and wp_remote_post() ...
}

Despite this, First Name, Last Name, Street Address, City, State, ZIP, etc. are still not appearing in the webhook payload.

Big Question is :

  • Is $field->inputs + checking customLabel / label / placeholder still the correct and reliable way in Gravity Forms?

I’d really appreciate an example of how to extract every individual part of Name and Address fields (with correct human-readable labels) inside gform_after_submission.

Thank you in advance!

The Name and Address fields have static data formats for their subinputs.

All of these assume the ID of your Name field is 1:

1.2 = Preview
1.3 = First Name
1.4 = Middle Name
1.6 = Last Name
1.8 = Suffix

All of these assume the ID of your Address field is 1:

1.1 = Address Line 1
1.2 = Address Line 2
1.3 = City
1.4 = State / Province / Region
1.5 = Zip / Postal Code
1.6 = Country

You can target any of these values from the $entry object like so:

$entry[1.1]

There are fancier ways to fetch this data but I’ve always found this to be the most straight forward, especially if you’re doing custom mapping.

Of course, I’d be remiss if I didn’t point out that we have an Airtable connection for Gravity Forms that would take all your troubles away. :magic_wand::wink:

Hey David, thanks!

That got it working!

1 Like

In case it’s helpful to the next person, here’s what ending up working for building the “$payload”.

I’ve noticed that it misses Names and Addresses after the first instance of each, but that could be solved by targeting fields by the label instead of the type.

$payload = new stdClass();

    foreach ( $form['fields'] as $field ) {
        if ( $field->is_administrative || $field->visibility === 'hidden' ) continue;

        $field_id = $field->id;

        // ——— NAME AND ADDRESS: Hardcoded reliable labels ———
        if ( $field->type === 'name' || $field->type === 'address' ) {
            if ( $field->type === 'name' ) {
                $payload->Prefix      = rgar( $entry, $field_id . '.2' ) ?? '';
                $payload->First       = rgar( $entry, $field_id . '.3' ) ?? '';
                $payload->Middle      = rgar( $entry, $field_id . '.4' ) ?? '';
                $payload->Last        = rgar( $entry, $field_id . '.6' ) ?? '';
                $payload->Suffix      = rgar( $entry, $field_id . '.8' ) ?? '';
            } elseif ( $field->type === 'address' ) {
                $payload->{'Street Address'} = rgar( $entry, $field_id . '.1' ) ?? '';
                $payload->{'Address Line 2'} = rgar( $entry, $field_id . '.2' ) ?? '';
                $payload->City               = rgar( $entry, $field_id . '.3' ) ?? '';
                $payload->State              = rgar( $entry, $field_id . '.4' ) ?? '';
                $payload->ZIP                = rgar( $entry, $field_id . '.5' ) ?? '';
                $payload->Country            = rgar( $entry, $field_id . '.6' ) ?? '';
            }
            continue;
        }

// ←←← CRITICAL: Skip if label is empty or just whitespace
        if ( $label === '' ) {
            continue; // Prevents empty key in JSON
        }

The rgar function accepts a third argument, the default value to return when there isn’t a value in the array for the specified key, so you could simplify your code slightly e.g.

$payload->Prefix      = rgar( $entry, $field_id . '.2', '' );
2 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.