Gossamer Forum
Home : Products : Gossamer Links : Discussions :

Drop down list with County by Country

Quote Reply
Drop down list with County by Country
Hiya

I am looking to create a single dropdown list during signup that contains all the counties in the Uk based on the country they are in. The aim is to make the selection easier by grouping counties by country but having the country display only.

For example

ENGLAND
Avon
Bedfordshire
Berkshire
SCOTLAND
Aberdeenshire
Angus
Argyll

How do I add the titles ENGLAND, SCOTLAND etc using the database editor

Cheers
Brinley
http://www.i-do-directory.com
Quote Reply
Re: [Brinley] Drop down list with County by Country In reply to
Hi,

The easiest way is to just add a list of the counties, and then use the Format_Select_Field() function available in the (free) plugin, ULTRAGlobals.

Code:
<%Plugins::ULTRAGlobals::Format_Select_Field($Test_Select,'Test_Select')%>
<select name="Test_Select">
<%loop select_loop%>
<option value="<%value%>" <%if selected%>selected="yes"<%endif%>><%name%></option>
<%endloop%>
</select>

Obviously add the new field, via Database > Links > Add Field. Setting something like this:

Form-Type: SELECT
Type: CHAR
Size: 255

Then enter you values in the box the "value" boxes, on this area.

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] Drop down list with County by Country In reply to
Hi Andy

Thx 4 replying - I'll give it a go!

Cheers
Brinley
http://www.i-do-directory.com
Quote Reply
Re: [Brinley] Drop down list with County by Country In reply to
Hi again

I am a bit confused, I have had a look at the globals which I gather purely allows you to display the field in a relevant template - which i can do

What i cant seem to do is add a "option group label" like ENGLAND below - am I missing something?

Quote:
<optgroup label="England">
<option value="Avon">Avon</option>

<option value="Bedfordshire">Bedfordshire</option>
<option value="Berkshire">Berkshire</option>
<option value="Bristol">Bristol</option>
<option value="Buckinghamshire">Buckinghamshire</option>
<option value="Cambridgeshire">Cambridgeshire</option>
<option value="Cheshire">Cheshire</option>

Cheers
Brinley
http://www.i-do-directory.com

Last edited by:

Brinley: Apr 19, 2008, 10:18 AM
Quote Reply
Re: [Brinley] Drop down list with County by Country In reply to
Hi,

Ah, right.

In that case - you could edit the /admin/Plugins/ULTRAGlobals.pm file, find:

Code:
#<%Plugins::ULTRAGlobals::Format_Select_Field($field,'Field')%>
sub Format_Select_Field {

my $current_value = $_[0];
my $field = $_[1];

my $schema = $DB->table('Links')->cols;
my $field_vals = $schema->{$field};
my @select_loop;
for (my $i = 0; $i <= 250; $i++) {
my $tmp;
if (!$field_vals->{form_values}[$i]) { last; }
$tmp->{value} = $field_vals->{form_values}[$i];
$tmp->{name} = $field_vals->{form_names}[$i];


if ($current_value eq $tmp->{name}) { $tmp->{selected} = 1; }
push @select_loop, $tmp;

}

return { select_loop => \@select_loop }

}

..and change like so:



Code:
#<%Plugins::ULTRAGlobals::Format_Select_Field($field,'Field')%>
sub Format_Select_Field {

my $current_value = $_[0];
my $field = $_[1];

my $schema = $DB->table('Links')->cols;
my $field_vals = $schema->{$field};
my @select_loop;
for (my $i = 0; $i <= 250; $i++) {
my $tmp;
if (!$field_vals->{form_values}[$i]) { last; }
$tmp->{value} = $field_vals->{form_values}[$i];
$tmp->{name} = $field_vals->{form_names}[$i];


if ($tmp->{name} =~ /England|Scotland|Wales/) {
$hit->{group_as} = 1;
}


if ($current_value eq $tmp->{name}) { $tmp->{selected} = 1; }
push @select_loop, $tmp;

}

return { select_loop => \@select_loop }

}

Then, instead of using:

Code:
<%Plugins::ULTRAGlobals::Format_Select_Field($Test_Select,'Test_Select')%>
<select name="Test_Select">
<%loop select_loop%>
<option value="<%value%>" <%if selected%>selected="yes"<%endif%>><%name%></option>
<%endloop%>
</select>

..try using:

Code:
<%Plugins::ULTRAGlobals::Format_Select_Field($Test_Select,'Test_Select')%>
<select name="Test_Select">
<%loop select_loop%>
<%if group_as%>
<optgroup label="<%name%>">
<%else%>
<option value="<%value%>" <%if selected%>selected="yes"<%endif%>><%name%></option>
<%endif%>

<%endloop%>
</select>

Totally untested - but should hopefully do what you need Smile

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!