Gossamer Forum
Home : Products : Gossamer Links : Discussions :

Re: [Anat] Select/Enum field in Form + how to create new pages

Quote Reply
Re: [Anat] Select/Enum field in Form + how to create new pages In reply to
You're right, the global in that post is not working.... try this global (called country_select):
Code:
sub {

my $element_name = shift;
my $selected_value = shift;
my $default_value = shift || 'United_States';


my @list = qw(
Afghanistan
Albania
Algeria
American_Samoa
Andorra

..............


Zambia
Zimbabwe

);

my $selected = $selected_value || $default_value;
$selected = { map {($_=>1)} ref $selected ? @$selected : $selected };

my $return = qq|<select name="$element_name"> |;
foreach my $country ( @list ) {
my $ischosen = $selected->{$country} ? ' selected="selected"' : '';
(my $country_nice = $country) =~ s,_, ,g;
$return .= qq|<option value ="$country" $ischosen>$country_nice</option>|;
}

$return .= q|</select>|;

return $return;
}
and use it as

<%country_select('Country',$Country,'France')%>

The first argument is the name of the select box, the second is there to display what is already selected, and the third can be used to set a default value (if nothing is selected).

Hope this works better...

Ivan
-----
Iyengar Yoga Resources / GT Plugins
Subject Author Views Date
Thread Select/Enum field in Form + how to create new pages Anat 9285 Aug 15, 2002, 2:15 PM
Post Re: [Anat] Select/Enum field in Form + how to create new pages
nt6 8947 Aug 15, 2002, 2:24 PM
Thread Re: [Anat] Select/Enum field in Form + how to create new pages
yogi 8932 Aug 15, 2002, 2:30 PM
Thread Re: [yogi] Select/Enum field in Form + how to create new pages
Anat 8929 Aug 15, 2002, 3:09 PM
Thread Re: [Anat] Select/Enum field in Form + how to create new pages
yogi 8953 Aug 15, 2002, 3:22 PM
Thread Re: [yogi] Select/Enum field in Form + how to create new pages
Anat 8952 Aug 16, 2002, 12:05 AM
Thread Re: [Anat] Select/Enum field in Form + how to create new pages
Anat 8945 Aug 16, 2002, 2:21 PM
Thread Re: [Anat] Select/Enum field in Form + how to create new pages
Anat 8891 Aug 16, 2002, 2:31 PM
Thread Re: [Anat] Select/Enum field in Form + how to create new pages
yogi 8956 Aug 17, 2002, 12:55 AM
Thread Re: [yogi] Select/Enum field in Form + how to create new pages
Anat 8869 Aug 17, 2002, 2:48 AM
Thread Re: [Anat] Select/Enum field in Form + how to create new pages
yogi 8923 Aug 17, 2002, 3:00 AM
Thread Re: [yogi] Select/Enum field in Form + how to create new pages
Anat 8904 Aug 17, 2002, 3:54 AM
Thread Re: [Anat] Select/Enum field in Form + how to create new pages
yogi 8880 Aug 17, 2002, 4:01 AM
Thread Re: [yogi] Select/Enum field in Form + how to create new pages
Anat 8898 Aug 17, 2002, 5:02 AM
Thread Re: [Anat] Select/Enum field in Form + how to create new pages
yogi 8882 Aug 17, 2002, 6:12 AM
Thread Re: [yogi] Select/Enum field in Form + how to create new pages
Anat 8875 Aug 17, 2002, 6:50 AM
Thread Re: [Anat] Select/Enum field in Form + how to create new pages
yogi 8886 Aug 17, 2002, 6:53 AM
Thread Re: [yogi] Select/Enum field in Form + how to create new pages
Anat 8853 Aug 17, 2002, 7:26 AM
Thread Re: [Anat] Select/Enum field in Form + how to create new pages
yogi 8898 Aug 17, 2002, 8:02 AM
Thread Re: [yogi] Select/Enum field in Form + how to create new pages
Anat 8852 Aug 17, 2002, 8:18 AM
Thread Re: [Anat] Select/Enum field in Form + how to create new pages
yogi 8893 Aug 17, 2002, 8:32 AM
Thread Re: [yogi] Select/Enum field in Form + how to create new pages
Anat 8929 Aug 17, 2002, 12:13 PM
Thread Re: [Anat] Select/Enum field in Form + how to create new pages
yogi 8921 Aug 17, 2002, 12:18 PM
Thread Re: [yogi] Select/Enum field in Form + how to create new pages
Anat 8891 Aug 17, 2002, 12:24 PM
Thread Re: [Anat] Select/Enum field in Form + how to create new pages
yogi 8936 Aug 17, 2002, 12:26 PM
Thread Re: [yogi] Select/Enum field in Form + how to create new pages
Anat 2030 Aug 17, 2002, 1:25 PM
Post Re: [Anat] Select/Enum field in Form + how to create new pages
yogi 2021 Aug 17, 2002, 1:28 PM
Thread Re: [yogi] Select/Enum field in Form + how to create new pages
Anat 2036 Aug 17, 2002, 10:54 PM
Post Re: [Anat] Select/Enum field in Form + how to create new pages
xpert 1916 Jul 13, 2003, 3:46 AM