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 9003 Aug 15, 2002, 2:15 PM
Post Re: [Anat] Select/Enum field in Form + how to create new pages
nt6 8668 Aug 15, 2002, 2:24 PM
Thread Re: [Anat] Select/Enum field in Form + how to create new pages
yogi 8655 Aug 15, 2002, 2:30 PM
Thread Re: [yogi] Select/Enum field in Form + how to create new pages
Anat 8650 Aug 15, 2002, 3:09 PM
Thread Re: [Anat] Select/Enum field in Form + how to create new pages
yogi 8674 Aug 15, 2002, 3:22 PM
Thread Re: [yogi] Select/Enum field in Form + how to create new pages
Anat 8673 Aug 16, 2002, 12:05 AM
Thread Re: [Anat] Select/Enum field in Form + how to create new pages
Anat 8666 Aug 16, 2002, 2:21 PM
Thread Re: [Anat] Select/Enum field in Form + how to create new pages
Anat 8612 Aug 16, 2002, 2:31 PM
Thread Re: [Anat] Select/Enum field in Form + how to create new pages
yogi 8676 Aug 17, 2002, 12:55 AM
Thread Re: [yogi] Select/Enum field in Form + how to create new pages
Anat 8591 Aug 17, 2002, 2:48 AM
Thread Re: [Anat] Select/Enum field in Form + how to create new pages
yogi 8643 Aug 17, 2002, 3:00 AM
Thread Re: [yogi] Select/Enum field in Form + how to create new pages
Anat 8623 Aug 17, 2002, 3:54 AM
Thread Re: [Anat] Select/Enum field in Form + how to create new pages
yogi 8600 Aug 17, 2002, 4:01 AM
Thread Re: [yogi] Select/Enum field in Form + how to create new pages
Anat 8619 Aug 17, 2002, 5:02 AM
Thread Re: [Anat] Select/Enum field in Form + how to create new pages
yogi 8605 Aug 17, 2002, 6:12 AM
Thread Re: [yogi] Select/Enum field in Form + how to create new pages
Anat 8597 Aug 17, 2002, 6:50 AM
Thread Re: [Anat] Select/Enum field in Form + how to create new pages
yogi 8606 Aug 17, 2002, 6:53 AM
Thread Re: [yogi] Select/Enum field in Form + how to create new pages
Anat 8574 Aug 17, 2002, 7:26 AM
Thread Re: [Anat] Select/Enum field in Form + how to create new pages
yogi 8618 Aug 17, 2002, 8:02 AM
Thread Re: [yogi] Select/Enum field in Form + how to create new pages
Anat 8573 Aug 17, 2002, 8:18 AM
Thread Re: [Anat] Select/Enum field in Form + how to create new pages
yogi 8616 Aug 17, 2002, 8:32 AM
Thread Re: [yogi] Select/Enum field in Form + how to create new pages
Anat 8649 Aug 17, 2002, 12:13 PM
Thread Re: [Anat] Select/Enum field in Form + how to create new pages
yogi 8640 Aug 17, 2002, 12:18 PM
Thread Re: [yogi] Select/Enum field in Form + how to create new pages
Anat 8612 Aug 17, 2002, 12:24 PM
Thread Re: [Anat] Select/Enum field in Form + how to create new pages
yogi 8656 Aug 17, 2002, 12:26 PM
Thread Re: [yogi] Select/Enum field in Form + how to create new pages
Anat 1958 Aug 17, 2002, 1:25 PM
Post Re: [Anat] Select/Enum field in Form + how to create new pages
yogi 1949 Aug 17, 2002, 1:28 PM
Thread Re: [yogi] Select/Enum field in Form + how to create new pages
Anat 1963 Aug 17, 2002, 10:54 PM
Post Re: [Anat] Select/Enum field in Form + how to create new pages
xpert 1844 Jul 13, 2003, 3:46 AM