Gossamer Forum
Home : Products : Gossamer Links : Development, Plugins and Globals :

Search box with a country drop down menu ?

Quote Reply
Search box with a country drop down menu ?
Hello,
I created a custom field "Country". With each link I add a country text (like "USA" or "Canada"....).

I would like to add a drop down menu next to the search box so users could enter their search and restrict it to a specific country.

What code would I need to add to the search form to perform this (if possible) ?

Also, I would like to have an "All" value so when user would select it in the drop down menu, it would search in ALL countries.

Cordially,
Brakkar
Quote Reply
Re: [brakkar] Search box with a country drop down menu ? In reply to
Should be able to just do it by putting a <select> box on the pages, and naming it 'Country' (or whatever you field name is). You can do search for stuff like this pretty simply with LSQL;

search.cgi?query=&Country=Country_Name

Hope that helps.

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Search box with a country drop down menu ? In reply to
Thanks for your answer, I'm glad to learn it is going to be possible.
I'm sorry for my lack of knowledge, but do you have an example of this running on a site ? I wish to see the code.


Thanks in advance,

Brakkar
Quote Reply
Re: [brakkar] Search box with a country drop down menu ? In reply to
Its very simple. The way I normally do it (rather than manually typing out each country, or field), is to go into the admin panel, click Links > Add, and then view the source there for the field in question, and paste it in the template you want to use it :)

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [brakkar] Search box with a country drop down menu ? In reply to
I have gotten so much useful information from this forum that it is my pleasure that I can provide the Global below. This pulls a list of countries from a table for a search drop-down. This only shows the countries that are already in the database. You can see it in action http://www.hightechtraveler.com/cgi-bin/search.cgi

Code:
sub usedGEO {
my $tags = shift;
my $table = $DB->table('GeoCodes','Links');
my $cond = GT::SQL::Condition->new('country','=',\'ccTLD');
$table->select_options ("ORDER BY CountryName");
my $sth = $table->select ('DISTINCT (country)',['country','ccTLD', 'countryName'],$cond);
my $output = '<select name="country"><option value="us">United States</option><option value="ca">Canada</option><option value=""> </option>';
while (my $row = $sth->fetchrow_hashref) {
$output .= '<option value='.$row->{ccTLD}.'>'.$row->{countryName}.'</option>';
}
$output .= '</select>';
return $output;
}

So what happens is:
a) Join my custom table and Links;
b) Create a condition - Links -> Country == GeoCodes -> ccTLD;
c) Make my table ordered by CountryName and only once per ccTLD;
d) Build my Dropdown (I put an extra "United States" and "Canada" at the top - you easily pull these);
e) and then in my searchbox template - i put <%usedGEO%> where I want to dropdown box to appear.