in reply to Drop down and display

It's been a couple of hours now and no one has dared to answer you. It's mostly because your code is complete rubbish, style- and functionality-wise. I guess that is because you do not understand HTML forms and interaction of them and the server program via the CGI. As such, it doesn't do what you aim to do.

Go read the synopsis of the CGI module first. Then come back and analyse this code (tested on command line only, not in web server environment):

#!/usr/bin/perl -T use strict; use diagnostics; use CGI (); use CGI::Carp qw/fatalsToBrowser/; my %labels = ( MA => 'Mortgage Advisers', CA => 'Customer Advisers', BM => 'Branch Management', HO => 'Head Office', Acc => 'Accord', MSa => 'MCC Sales', MSe => 'MCC Service', ); my $cgi = CGI->new; print $cgi->header('text/html'); my $dept = $cgi->param('department'); if (defined $dept) { if (exists $labels{$dept}) { # FIXME # untaint $dept and put it into database print $cgi->start_html, $cgi->p("$dept was received."), $cgi->end_html; } else { print $cgi->start_html, $cgi->p("$dept was received, but is not a valid department + name."), $cgi->end_html; }; } else { print $cgi->start_html, $cgi->start_form( -action => $cgi->script_name, ), $cgi->popup_menu( -name => 'department', -values => [keys %labels], -labels => \%labels, ), $cgi->submit, $cgi->end_form, $cgi->end_html; };

Replies are listed 'Best First'.
Re^2: Drop down and display
by kjg (Sexton) on Apr 13, 2006 at 15:54 UTC
    That's brilliant - it works. Now I just need to get it to query a SQL database using that value as part of the query.

    If I get stuck I'll ask another question - I need to get to grips with the CGI.pm before I do anything else!