The search bar lets users look up any country in the REST Countries database without clicking the map. It accepts English common names (e.g.,Documentation Index
Fetch the complete documentation index at: https://mintlify.com/AndresLopezCorrales/Countries-WebPage/llms.txt
Use this file to discover all available pages before exploring further.
Germany) and official names (e.g., Federal Republic of Germany). The input is located in the top navigation bar and is always visible, making it the fastest way to reach countries that are hard to click on the map or whose shapes are too small to target.
Using the search bar
Type the country name
Enter the country name in English into the input field labeled Search for a country in the navigation bar.
Valid search formats
The table below shows examples of inputs that succeed and inputs that fail, so you can predict how the app will respond.| Input | Result |
|---|---|
Germany | Federal Republic of Germany ✓ |
Federal Republic of Germany | Same result as above ✓ |
Deutschland | Error — not English or official name ✗ |
Spain | Kingdom of Spain ✓ |
United States | United States of America ✓ |
japan | Japan ✓ (case-insensitive at the API level) |
How search works
The search form inindex.php uses method="post" with a text field named search and a submit button named submit. When the form is submitted, the PHP backend processes it through the following flow:
ApiConsumer::searchBar()checks for bothisset($_POST['submit'])andisset($_POST['search']). If both are set, it returns the value of$_POST['search']; otherwise it returns an empty string.ApiConsumer::getSearchBarInfo()callssearchBar()first. If a non-empty string is returned, it is used as the country name. If the search bar is empty, the method falls back toGetNameController::clickCountries(), which reads$_POST['titulo']from a map click.- The country name has its spaces replaced with
%20usingstr_replace()before being interpolated into the API URL:https://restcountries.com/v3.1/name/{name}.
The search is case-insensitive at the REST Countries API level, but the name must be in English. The popover info button (the ⓘ icon in the navbar) also displays this reminder in both English and Spanish: “The country names are ONLY VALID if they are in the english language or putting their official name.”
Error handling
When the submitted name does not match any country in the REST Countries database, the API returns a JSON error object. Country-Click detects two conditions and renders an error message in both cases:- The response JSON contains
"status": 404 - The response JSON contains
"message": "Page Not Found"
ApiConsumer.php
file_get_contents() returns false (a network failure or unreachable host), the exception is caught and the same error message style is displayed.
Frequently asked questions
Why does my country name not work?
Why does my country name not work?
The app queries the REST Countries API using English names only. If the common English name fails, try the country’s official name. For example, if
Ivory Coast does not return results, try Côte d'Ivoire. The API’s /name/ endpoint performs a partial-match search, so both forms often work — but non-English names (e.g., German, French, or local names) will always return a 404 error.Can I search by capital city?
Can I search by capital city?
No. The app queries the REST Countries API exclusively via the
/v3.1/name/ endpoint, which matches on country names only. Searching for a capital such as Berlin or Tokyo will return a 404 error because those strings do not match any country name in the database.What happens if I leave the search blank and press Buscar?
What happens if I leave the search blank and press Buscar?
Submitting an empty search field causes
ApiConsumer::searchBar() to return an empty string. getSearchBarInfo() then checks whether a map click ($_POST['titulo']) is also absent. If both are empty, no API request is made and the info panel remains blank. No error message is shown.