0

I am trying to create an action hook on before sending an email for left trimming for my phone input where I need to trim the '+' character from the input received on Contact Form 7. The input receives a full valid international number with '+' character as a prefix. So I created a code for removing such but unfortunately, it doesn't work.

Here is the code:

/*Before Send Mail Function - LTRIM*/
add_action( 'wpcf7_before_send_mail', 'wpcf7_intl_tel_before_send_mail' );

function wpcf7_intl_tel_before_send_mail( $wpcf7 ) {
    $submission = WPCF7_Submission::get_instance();
 if ( $submission ) {
     $posted_data = $submission->get_posted_data();
 }
 
 if( $wpcf7->id() == 1671 ) {
  $intl_phone = sanitize_text_field( $posted_data['intl_tel-797'] );
  $intl_phone = ltrim( $intl_phone, $intl_phone[0] );
        //$intl_phone = ltrim( $intl_phone, '+' );
 }
 return $intl_phone;
}
1671 is the Contact Form ID generated and intl_tel-797 is the telephone input ID.

Any help would be appreciated.

Thanks in advance!

Krupal Panchal
  • 1,553
  • 2
  • 13
  • 26

0 Answers0