I have a client that uses a phone system that supports matching phone numbers that are stored in a custom field in ActiveCampaign with callers. The hitch is that it requires the numbers to be stored without formatting. Is there any way that I can remove the parentheses, space, and dash from phone numbers before processing the entry? I tried the following code, but it seems to reformat the data after the trigger is called:
add_action( ‘gform_pre_submission’, ‘gform_compress_phone_numbers’, 10, 1 );
function gform_compress_phone_numbers( $form ) {
GFCommon::log_debug( METHOD . ‘(): ORIGINAL POST’ . print_r( $POST, true ) );
foreach ( $form[‘fields’] as $field ) {
if ( $field[‘type’] == ‘phone’ ) {
GFCommon::log_debug( METHOD . ‘(): I found a phone number field!’ . print_r( $field, true ) );
$field = 'input’ . $field[‘id’];
$org_value = rgpost ( $field );
GFCommon::log_debug( METHOD . “(): Original value => {$org_value}.” );
$_POST[“{$field}”] = preg_replace(‘/[^0-9]/’, ‘’, $org_value);
GFCommon::log_debug( METHOD . ‘(): Altered POST’ . print_r( $_POST, true ) );
}
}
}
If you want to send just digits to ActiveCampaign, and your regex works, you could use this filter instead (still store the data in the format you collected it in, but alter it when sending to ActiveCampaign):
The filter name for ActiveCampaign is gform_activecampaign_field_value.
If you need help converting your code over to use this filter instead, let us know.