Skip to content

feat: support GF 3.0 International (formatted) phone numbers - #1689

Merged
jakejackson1 merged 1 commit into
hot-patch-6.16.0from
fix/gf3-international-phone
Jul 27, 2026
Merged

feat: support GF 3.0 International (formatted) phone numbers#1689
jakejackson1 merged 1 commit into
hot-patch-6.16.0from
fix/gf3-international-phone

Conversation

@jakejackson1

@jakejackson1 jakejackson1 commented Jul 27, 2026

Copy link
Copy Markdown
Member

What

Gravity Forms 3.0 adds an International (formatted) phone format that stores the value as a JSON object in the entry. Gravity PDF had no support for it, so it printed the raw JSON:

{"country":"US","national":"2015551232","formatted":"(201) 555-1232","e164":"+12015551232"}

Field_Phone now renders the ISO country code, the dial code, and the formatted number. The dial code is dropped when the field's Show country dial code setting is off, mirroring what the user saw on screen:

Setting PDF output
Enabled (GF default) US +1 (201) 555-1232
Disabled US (201) 555-1232

Detection keys off the stored entry value being JSON, not the field's phoneFormat setting. Entries saved while the field was International (formatted) therefore still display correctly after the field is switched to a format that doesn't store JSON — otherwise those existing entries would revert to showing raw JSON.

Why the dial code is derived rather than looked up

It's obtained by removing the national number from the tail of the E.164 number. Two PHP-side alternatives were checked and rejected:

  • GF_Field_Phone::get_dial_code() reads assets/js/src/theme/fields/international-phone/countries.json. That file is not in the distributed Gravity Forms zip (only assets/js/dist/ ships), so it returns an empty string in a real install. It's also private static.
  • E164Validator::validate( $e164, true ) does return the dial code, but it's GF 2.9+ while Gravity PDF supports 2.5+, it's an undocumented internal in the global namespace, and the first call loads a 254 KB rules array.

$form_data

$form_data['field'] keeps the displayed number as a string, so templates that echo it keep working if a site switches an existing phone field to the new format. The parts are exposed under a new phone key:

$form_data['field'][14]         // 'US +1 (201) 555-1232'
$form_data['field']['14.Phone'] // 'US +1 (201) 555-1232'
$form_data['field']['Phone']    // 'US +1 (201) 555-1232'

$form_data['phone'][14] => [
    'country'   => 'US',
    'dial_code' => '+1',
    'national'  => '2015551232',
    'formatted' => '(201) 555-1232',
    'e164'      => '+12015551232',
]

This follows the Field_List / Field_Signature precedent of putting structured data under its own top-level key, and 'phone' was added to gfpdf_form_data_key_order.

⚠️ As with the existing list and signature_details_id keys, $form_data['phone'] is not populated for phone fields inside a Repeater, because Field_Repeater merges only the field and html_id keys from its sub-fields. Worth a docs note.

Testing

11 new tests in tests/phpunit/unit-tests/Helper/Fields/Test_Field_Phone.php, covering the US and multi-digit (GB +44) dial-code derivation, both showCountryCode states plus the unset default, the format-switch case, non-JSON pass-through, unrecognised JSON, and $form_data for both shapes. The fixture is built in memory, so it touches no database.

Full suite run against the branch: 1162 tests, 3602 assertions. PHPCS and phpcompat (PHP 7.3 floor) both clean.

Notes for review

  • Changelog entries are filed under the existing 6.16.0 release, as a 🎉 Feature alongside the existing "Gravity Forms 3.0 compatibility" line.
  • Behaviour is unchanged for US Standard and International (unformatted) phone fields.

🤖 Generated with Claude Code

Gravity Forms 3.0 adds an International (formatted) phone number format
that stores the value as a JSON object in the entry, so PDFs printed the
raw JSON:

    {"country":"US","national":"2015551232","formatted":"(201) 555-1232","e164":"+12015551232"}

Field_Phone now renders the ISO country code, the dial code, and the
formatted number. The dial code is omitted when the field's "Show country
dial code" setting is disabled, matching what the user saw on-screen:

    US +1 (201) 555-1232    (setting enabled)
    US (201) 555-1232       (setting disabled)

Detection is based on the stored entry value being JSON, not on the
field's phoneFormat setting, so entries saved while the field was
International (formatted) still display correctly after the field is
switched to a format that doesn't store JSON.

The dial code is derived by removing the national number from the tail of
the E.164 number rather than looked up. Gravity Forms resolves it from
assets/js/src/theme/fields/international-phone/countries.json, which is
not present in the distributed plugin zip, so GF_Field_Phone::get_dial_code()
returns an empty string in a real install. GF 3.0 also ships
E164Validator::validate(), which returns the dial code, but it is GF 2.9+
only (Gravity PDF supports 2.5+), lives in the global namespace as an
undocumented internal, and loads a 254KB rules array on first use.

$form_data['field'] keeps the displayed number as a string so existing
templates continue to work when a phone field is switched to the new
format. The individual parts are exposed under a new $form_data['phone']
key, following the Field_List and Field_Signature precedent.

Note that, as with the existing 'list' and 'signature_details_id' keys,
$form_data['phone'] is not populated for phone fields inside a Repeater,
because Field_Repeater merges only the 'field' and 'html_id' keys from
its sub-fields.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@jakejackson1
jakejackson1 force-pushed the fix/gf3-international-phone branch from 95ddf77 to 2e666a6 Compare July 27, 2026 05:52
@jakejackson1 jakejackson1 changed the title fix: display GF 3.0 International (formatted) phone numbers feat: support GF 3.0 International (formatted) phone numbers Jul 27, 2026
@jakejackson1
jakejackson1 merged commit 534ceef into hot-patch-6.16.0 Jul 27, 2026
13 of 14 checks passed
@jakejackson1
jakejackson1 deleted the fix/gf3-international-phone branch July 27, 2026 06:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant