From 659b1e1bace426a7be82bd7a761b0916d0f66d33 Mon Sep 17 00:00:00 2001 From: tellyworth Date: Tue, 24 Nov 2026 10:43:19 +1100 Subject: [PATCH] Capture phone numbers from Jetpack form phone fields that use the country selector Jetpack Forms gives a phone field the type 'phone' when its country selector is on, and 'telephone' otherwise. The form capture only matched 'telephone', so the contact was created without its phone number. Co-Authored-By: Claude Fable 5.2 --- includes/ZeroBSCRM.Jetpack.php | 3 ++- .../Jetpack_Form_Capture_Values_Test.php | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/includes/ZeroBSCRM.Jetpack.php b/includes/ZeroBSCRM.Jetpack.php index 182926c7..0236248f 100644 --- a/includes/ZeroBSCRM.Jetpack.php +++ b/includes/ZeroBSCRM.Jetpack.php @@ -139,7 +139,8 @@ function zero_bs_crm_capture_jetpack_form( $post_id, $all_field_data, $is_spam, $contact_data['email'] = jpcrm_jetpack_form_text_value( $field_data->value ); } - if ( 'telephone' === $field_data->get_attribute( 'type' ) + // A phone field with the country selector switched on has the type 'phone'. + if ( in_array( $field_data->get_attribute( 'type' ), array( 'telephone', 'phone' ), true ) && ! isset( $contact_data['hometel'] ) && ! empty( $field_data->value ) ) { diff --git a/tests/php/entities/Jetpack_Form_Capture_Values_Test.php b/tests/php/entities/Jetpack_Form_Capture_Values_Test.php index 5e90e869..49369bdb 100644 --- a/tests/php/entities/Jetpack_Form_Capture_Values_Test.php +++ b/tests/php/entities/Jetpack_Form_Capture_Values_Test.php @@ -121,6 +121,25 @@ public function test_an_ordinary_submission_is_stored_as_sent() { $this->assertSame( '+353 (21) 427-0000', $contact['hometel'] ); } + /** + * @testdox A phone field with the country selector is stored as the contact's phone number. + */ + #[TestDox( 'A phone field with the country selector is stored as the contact\'s phone number.' )] + public function test_a_phone_field_with_the_country_selector_is_stored() { + + $this->submit( + array( + $this->form_field( 'g1-email', 'email', 'astrid@example.test' ), + $this->form_field( 'g1-phone', 'phone', '+46 701234567' ), + ) + ); + + $contact = $this->contact_with_email( 'astrid@example.test' ); + + $this->assertIsArray( $contact, 'No contact was created.' ); + $this->assertSame( '+46 701234567', $contact['hometel'] ); + } + /** * @testdox Submitted values are stored as plain text. */