Bhrugesh Bavishi
Bhrugesh Bavishi

Reputation: 93

Contact Form 7 country list

I want Get Current country(Find by IP) in cf 7 dropdown.

Below I find the country by IP:

function wpcf7_custom_date_shortcode_handler($mycountry) {

$myipd = get_client_ip(); 
$url = 'http://www.geoplugin.net/json.gp?ip='.$myipd; 
$details    =   ip_details($url); 

$v = json_decode($details);
$mycountry = $v->geoplugin_countryName;
return $mycountry;
}


function get_client_ip() {
 $ipaddress = '';
 if (getenv('HTTP_CLIENT_IP'))
    $ipaddress = getenv('HTTP_CLIENT_IP');
 else if(getenv('HTTP_X_FORWARDED_FOR'))
    $ipaddress = getenv('HTTP_X_FORWARDED_FOR');
 else if(getenv('HTTP_X_FORWARDED'))
    $ipaddress = getenv('HTTP_X_FORWARDED');
 else if(getenv('HTTP_FORWARDED_FOR'))
    $ipaddress = getenv('HTTP_FORWARDED_FOR');
 else if(getenv('HTTP_FORWARDED'))
    $ipaddress = getenv('HTTP_FORWARDED');
 else if(getenv('REMOTE_ADDR'))
    $ipaddress = getenv('REMOTE_ADDR');
 else
    $ipaddress = 'UNKNOWN';

 return $ipaddress;
}

function ip_details($url) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
$data = curl_exec($ch);
curl_close($ch);

return $data;
}

Below the contact form 7 form tag:

Country[select* countrylist id:Country "Please Select a Country" "United States|USA" "Afghanistan|AFG" "Albania|ALB" "Algeria|DZA" "American Samoa|ASM" ........ ]

(Note: ..... means list all countries defined)

Upvotes: 0

Views: 674

Answers (1)

Hritik Pandey
Hritik Pandey

Reputation: 949

you can use this plugin to achieve user tracking details in form email. Lead info with country for Contact Form 7

Upvotes: 2

Related Questions