CF7-Country-Phone-Field

CF7 Country Phone Field

A powerful WordPress plugin that enhances Contact Form 7 with a country phone input field. Displays country flags and codes dynamically, with custom search functionality.

Bd Country Flags Contact Form 7 Plugin

Version: 2.0

Developer: Barış Dayak

Official Website: Barış Dayak Official Website

Features

Installation

1.Download the Plugin: Clone or download this repository from GitHub. 2.Upload to WordPress: Upload the plugin folder to your WordPress installation under /wp-content/plugins/. 3.Activate the Plugin:Go to the WordPress Admin Panel and activate the plugin under the Plugins menu.


preview1 preview2

Plugin Description

Bd Country Flags Contact Form 7 is a WordPress plugin that enhances Contact Form 7 by adding a custom phone input field with country flags. It provides a more professional and user-friendly experience for form submissions.


Note !

✨ Form Integration Guide

To integrate the phone number input field with country flags into Contact Form 7 forms, you need to add the following HTML structure inside your form template:


<label>Phone Number</label>
<div class="select-box">
    <div class="selected-option">
        <div>
            <span class="iconify"></span>
            <strong>+1</strong>
        </div>
        <input type="tel" name="phone-number" placeholder="Phone Number" required>
    </div>
    <div class="options">
        <input type="text" class="search-box" placeholder="Country Search...">
        <ol></ol>
    </div>
</div>

💻 Add PHP Code to functions.php

To ensure proper backend processing of the phone number input field in Contact Form 7, add the following code to your theme's functions.php file:


<?php
// Register the shortcode for Contact Form 7
add_shortcode('country_phone', 'cf7_country_phone_shortcode');

function cf7_country_phone_shortcode($atts) {
    $atts = shortcode_atts(
        array(
            'name' => 'phone-number', // The name attribute of the form input
        ),
        $atts,
        'country_phone'
    );

    // Retrieve form data after submission
    $submission = WPCF7_Submission::get_instance();
    if ($submission) {
        $posted_data = $submission->get_posted_data();

        // Return the phone number if available
        if (!empty($posted_data[$atts['name']])) {
            return sanitize_text_field($posted_data[$atts['name']]);
        }
    }
    return 'Phone number not provided';
}

// Force shortcode processing in form elements
add_filter('wpcf7_form_elements', 'do_shortcode_for_cf7');
function do_shortcode_for_cf7($form) {
    return do_shortcode($form);
}

// Append shortcode result to the email body
add_filter('wpcf7_mail_components', 'cf7_add_country_phone_to_mail', 10, 3);
function cf7_add_country_phone_to_mail($mail_components, $contact_form, $instance) {
    $shortcode_output = do_shortcode('[country_phone name="phone-number"]');

    // Add phone number to the email body if available
    if (!empty($shortcode_output) && $shortcode_output !== 'Phone number not provided') {
        $mail_components['body'] .= "\nCountry Code and Phone: " . $shortcode_output;
    } else {
        $mail_components['body'] .= "\nCountry Code and Phone: Phone number not provided";
    }
    return $mail_components;
}
?>

Plugin Features

1. Country Codes and Flags


2. Default Country Code Setup


4. Admin Email Notifications


5. Dynamic Search Feature


6. Full Customization Support


7. Responsive Design


👨‍💻 About Barış Dayak

Barış Dayak is an experienced web developer specializing in WordPress web design and custom plugin development. He has contributed to numerous professional projects, helping businesses succeed online with innovative digital solutions.

🚀 Created by Barış Dayak - WordPress Expert.