function ip2country_admin_settings_submit in IP-based Determination of a Visitor's Country 6
Same name and namespace in other branches
- 7 ip2country.admin.inc \ip2country_admin_settings_submit()
Processes forms submitted by IP to Country administration page.
See also
1 string reference to 'ip2country_admin_settings_submit'
- ip2country_admin_settings in ./
ip2country.admin.inc - Default IP to Country administration settings.
File
- ./
ip2country.admin.inc, line 256 - Determination of user's Country based on IP address.
Code
function ip2country_admin_settings_submit($form, &$form_state) {
global $user;
// Exclude unnecessary elements from being saved in variable table.
unset($form_state['values']['ip2country_update_database'], $form_state['values']['ip2country_lookup'], $form_state['values']['ip2country_lookup_button']);
// Check to see if debug set.
if ($form_state['values']['ip2country_debug']) {
// Debug on.
if ($form_state['values']['ip2country_test_type']) {
// Dummy IP Address.
$ip = $form_state['values']['ip2country_test_ip_address'];
$country_code = ip2country_get_country($ip);
}
else {
// Dummy Country.
$country_code = $form_state['values']['ip2country_test_country'];
}
drupal_set_message(t('Using DEBUG value for Country - @country', array(
'@country' => $country_code,
)));
}
else {
// Debug off - make sure we set/reset IP/Country to their real values.
$ip = ip_address();
$country_code = ip2country_get_country($ip);
drupal_set_message(t('Using ACTUAL value for Country - @country', array(
'@country' => $country_code,
)));
}
// Finally, save country, if it has been determined.
if ($country_code) {
// Store the ISO country code in the $user object.
user_save($user, array(
'country_iso_code_2' => $country_code,
));
}
}