I've managed to pull together a way to populate a 'Country' dropdown menu from a txt file, with all of the options on a line each.
The value of each item is given an incrementing number, and passes this through fine.
But how can I pass through the contents of the line from the text file, without having to create a massive switch for each of the number values, to set the country?
<select class="country-select" name="country" tabindex = '9' >
<?php
$lines = file( 'country-list.txt' );
for ($i = 0; $i < count($lines);$i++) {
echo '<option value=' . ($i + 1) . '>' . $lines[$i] . '</option>';
}
?>
</select>
$name = clearData($_POST["name"]);
$country = ($_POST["country"]);
$phone = ($_POST["phone"]);
A small portion of my country file:
Your Country
-
Afghanistan
Albania
Algeria
American Samoa
Andorra
Angola
Anguilla
Antarctica
Antigua/Barbuda
Argentina
Armenia
Aruba
Australia
It's worth saying, that the email response I receive, shows the number of the value. Which is the line number in the text file, and that corresponds to the correct country chosen in the dropdown menu. So it is selecting and passing through the correct country.