I have already followed your suggestions for this issue, But still not working

Hi,

Hi, is there a way to automatically remove spaces and dashes in the phone field? So that if the client enters the telephone number in the wrong format it will automatically be corrected.

example client input like this:
+60 1234-56789

Autofix to:
+60123456789

I’m currently using the additional Smartphone field for the Gravity Forms plugin to add flags and use the phone field (international)

The form is on this page: https://www.unimy.edu.my/enquire-now/

Your Suggestion is
Hi Shakirah,

There’s no built-in feature to remove specific characters from the field values, but you could use the gform_save_field_value filter and some custom code to remove those characters before saving the value into the database. The filter documentation has an example that points you into the right direction: docs.gravityforms.cm/gform_save_field_value/#h-5-remove-new-lines-tabs-and-carriage-returns*

Please check the following link for details and options available to insert custom PHP code: docs.gravityforms.cm/where-do-i-put-this-code/php*

Regards,

I try to add this code to:

add_filter( 'gform_activecampaign_field_value', 'gform_truncate_phone_numbers', 10, 4 );
function gform_truncate_phone_numbers( $value, $form, $entry, $field_id ) {
    $field = GFAPI::get_field( $form, $field_id );
 
    if ( is_object( $field ) && ( $field->type == 'phone' ) ) {
        $value = preg_replace('/[^0-9]/', '', $value);
    }
 
    return $value;
}

with plugin edit snippet, but still not working…

Note that this filter will only affect the values that are being sent through ActiveCampaign feeds. If you want to apply the same transformation for values saved in Gravity Forms, you will want to also hook into the filter gform_save_field_value.

Hi, Joshua, can you help me with how to do it, I have tried several ways not working.

I only need a way to automatically remove spaces and dashes in the phone field? So that if the client enters the telephone number in the wrong format it will automatically be corrected.

example client input like this:
+60 1234-56789

Autofix to:
+60123456789

I’m currently using the additional Smartphone field for the Gravity Forms plugin to add flags and use the phone field (international)

The form is on this page: https://www.unimy.edu.my/enquire-now/

If you are willing to change the phone field to a single-line text field you can then change the input mask. I’ve attached a screenshot with a few steps. Also, a documentation link is below.

Input Mask

1 Like

Hi Derek, thanks, Our client wants to add a country flag on the phone field.
And it requires an additional Smartphone field plugin for the Gravity Forms plugin to add flags and this plugin needs to use a phone field (international).

Like this: The form is on this page: https://www.unimy.edu.my/enquire-now/

With this add-on, which you might be referring to, according to their documentation you can select one input mask and apply it for all countries while still keeping the flags. The link above has a screenshot of the settings you need to toggle to do this .

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.