Search code examples
phpformswordpressgravity

Get gravity forms input value for address field


How do I get the value of the address input element inside the gform_after_submission hook in Gravity Forms? I can get values of the other fields with

add_action('gform_after_submission_1', 'post_signup_info', 10, 2);

 function post_signup_info($entry, $form) {
    $name = $entry['1']; //This works
    $address = $entry['2']; //This doesn't.
}

Where name is a text field with id 1, and address is an address field with id 2.

The Gravity Forms documentation says that address fields are represented as an array, but the $address variable in the example above is empty.

How do I access the address field value?


Solution

  • The address field array is stored a bit differently. Try using these values. The example below assumes your address field ID starts with 2.

    $street = $entry["2.1"];
    $street2 = $entry["2.2"];
    $city = $entry["2.3"];
    $state = $entry["2.4"];
    $zip = $entry["2.5"];
    $country = $entry["2.6"];