Skip to content

Commit a09d644

Browse files
committed
gpapf-save-national-format.php: Added new snippet.
1 parent 962bcde commit a09d644

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

gp-advanced-phone-field/gpapf-save-national-format.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
// Update "123" to your form ID and "4" to your Phone field ID.
1111
add_action( 'gform_save_field_value_123_4', function( $value, $entry, $field, $form, $input_id ) {
1212

13-
if ( ! is_callable( 'gp_advanced_phone_field' ) || ! class_exists( '\libphonenumber\PhoneNumberUtil' ) ) {
13+
if ( ! is_callable( 'gp_advanced_phone_field' ) || ! class_exists( '\libphonenumber\PhoneNumberUtil' ) || rgget( 'page' ) != 'gf_entries') {
1414
return $value;
1515
}
1616

@@ -19,6 +19,11 @@
1919
if ( ! $proto ) {
2020
return $value;
2121
}
22-
return $phone_number_util->format( $proto, \libphonenumber\PhoneNumberFormat::NATIONAL );
22+
try {
23+
return $phone_number_util->format( $proto, \libphonenumber\PhoneNumberFormat::NATIONAL );
24+
} catch ( Exception $e ) {
25+
error_log( 'Error formatting phone number: ' . $e->getMessage() );
26+
return $value;
27+
}
2328

2429
}, 10, 5 );

0 commit comments

Comments
 (0)