Here you can change the old country list for account-signup, and use a new better one with jQuery and select2 plugin.
Members can also search for a country in the dropdown field and easily locate a country without endless scrolling. Increases UX and encourages field population from members.
Open header.php and add (CDN):
Now open account-signup and find
Replace with
Now run SQL query
Now upload "countries" folder from ZIP file into /images/
Works like this
[ATTACH type="full" width="609px" alt="County-List-TTv3.png"]5436[/ATTACH]
Enjoy!
Members can also search for a country in the dropdown field and easily locate a country without endless scrolling. Increases UX and encourages field population from members.
Open header.php and add (CDN):
<link href="https://cdn.jsdelivr.net/npm/select2@4.0.13/dist/css/select2.min.css" rel="stylesheet" />
<script src="https://cdn.jsdelivr.net/npm/select2@4.0.13/dist/js/select2.min.js"></script>
<script>
function formatCountry (country) {
if (!country.id) { return country.text; }
var baseUrl = "<?php echo $site_config["SITEURL"]; ?>/images/countries";
var $country = $(
'<span><img src="' + baseUrl + '/' + country.text.toLowerCase() + '.png" class="img-flag" style="vertical-align:middle;width:25px;height:25px;margin-right:7px" />' + country.text + '</span>'
);
return $country;
};
$("#countries").select2({
templateResult: formatCountry
});
</script>
Now open account-signup and find
<tr>
<td><?php echo T_("COUNTRY"); ?>:</td>
<td>
<select name="country" size="1">
<?php
$countries = "<option value=\"0\">---- ".T_("NONE_SELECTED")." ----</option>\n";
$ct_r = SQL_Query_exec("SELECT id,name,domain from countries ORDER BY name");
while ($ct_a = mysql_fetch_assoc($ct_r)) {
$countries .= "<option value=\"$ct_a[id]\">$ct_a[name]</option>\n";
}
?>
<?php echo $countries; ?>
</select>
</td>
</tr>
Replace with
<tr>
<td><?php echo T_("COUNTRY"); ?>:</td>
<td>
<?php
// Include database
$dsn = 'mysql:dbname=database;host=localhost;charset=utf8';
$user = 'username;
$password = 'password';
try {
$db = new PDO($dsn, $user, $password);
$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); // Prevent advanced injection by disabling emulated prepared statements
$query = $db->prepare("SELECT * FROM countries ORDER BY name");
$result = $query->fetchAll(PDO::FETCH_ASSOC);
if ($query->execute()) {
while ($lang_a = $query->fetch()) {
$langimage = $site_config["SITEURL"] . '/images/countries/' . $lang_a['flagpic'];
$lang_id = $lang_a['id'];
$lang_name = $lang_a['name'];
$lang_sa[$lang_name] = $lang_id;
$languages .= "<option value='$lang_id'$lang>$lang_name</option>";
}
}
}
catch (PDOException $e) {
echo "Error!: " . $e->getMessage() . "<br/>";
die();
}
?>
</select>
</td>
</tr>
<script>
function formatState (state) {
if (!state.id) {
return state.text;
}
var baseUrl = "<?php echo $site_config["SITEURL"]; ?>/images/countries";
var $state = $(
'<span><img src="' + baseUrl + '/' + state.text.toLowerCase() + '.png" class="img-flag" style="vertical-align:middle;width:25px;height:25px;margin-right:7px" />' + state.text + '</span>'
);
return $state;
};
$("#countries").select2({
templateResult: formatState
});
</script>
<select name="country" id="countries">
<?php echo $languages; ?>
</select>
Now run SQL query
UPDATE countries
SET flagpic = REPLACE(flagpic, 'gif', 'png')
WHERE flagpic LIKE '%gif%'
Now upload "countries" folder from ZIP file into /images/
Works like this
[ATTACH type="full" width="609px" alt="County-List-TTv3.png"]5436[/ATTACH]
Enjoy!

