Home > Archive > PERL Beginners > July 2006 > Dynamically choosing CGI file based on form output
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Dynamically choosing CGI file based on form output
|
|
| Mike Martin 2006-07-27, 6:57 pm |
| I have the following code which should
1. Give user a choice of actions
2. Based on these go to the specified script
I have the following issues
1. The Submit button needs clicking twice after selection
2. Only one value can be chosen, to choose another the form must be
reloaded from scratch (ie: reload button does not work, only go etc)
Any assistance appreciated
Script follows
#!/usr/bin/perl -wT
use CGI qw/:standard/;
use strict;
use CGI::Carp qw/warningsToBrowser fatalsToBrowser/;
## sub to print submit button;
sub run_cmd1 {return print
span({-class=>'place_cmd'},submit(-name=>'act', -value=>shift)),p};
##selection hash;
my %commands1=(1=>['Choose
Operation',''],2=>['correspondence',''],3=>['file
management',''],4=>['filing'.''],5=>['Finance','/cgi-bin/finance.pl'],6=>['Contacts','/cgi-bin/contacts.pl'],7=>['Telephone
Logging',''],8=>['Timesheets','/cgi-bin/timesheet.pl'],9=>['Calendars','']);
print header();
&head1;
sub head1 {
## transalation of drop-down list to actions;
print start_html(-style=>'/proj.css');
my $command;
$command=param('select');
if (param('select')){
foreach my $keys (keys %commands1){
if (param('select') eq $keys){
$command= $commands1{$keys}[1];}}}
print start_multipart_form (-method=>'POST',-action=>$command),
"user",br,textfield(-name=>'user',-size=>'15'),br,
"password",br,password_field(-name=>'pass'),br;
my @select;
my %select;
foreach my $keys (sort(keys %commands1)){push (@select,$keys);
$select{$keys}=$commands1{$keys}[0]
}
## select pop_up menu;
print popup_menu(-name=>'select',-values=>[@select],-default=>$commands1{1}[0,-labels=>\%select);
run_cmd1('Chooser');
print end_form;
print end_html}
| |
| Paul Lalli 2006-07-27, 6:57 pm |
| Mike Martin wrote:
> I have the following code which should
>
> 1. Give user a choice of actions
> 2. Based on these go to the specified script
>
> I have the following issues
>
> 1. The Submit button needs clicking twice after selection
> 2. Only one value can be chosen, to choose another the form must be
> reloaded from scratch (ie: reload button does not work, only go etc)
>
> Any assistance appreciated
>
> Script follows
>
> #!/usr/bin/perl -wT
> use CGI qw/:standard/;
> use strict;
> use CGI::Carp qw/warningsToBrowser fatalsToBrowser/;
<snip the rest>
GAAAH. My eyes!! What do you have against whitespace?! How can you
expect anyone - yourself or others - to read that code?
*PLEASE*, format your code into some semblance of something readable,
and try again. Read perldoc perlstyle if you don't know how Perl
programs *should* look.
Paul Lalli
| |
|
|
| DJ Stunks 2006-07-27, 6:57 pm |
|
usenet@DavidFilmer.com wrote:
> Mike Martin wrote:
>
>
> Begin here:
>
> http://search.cpan.org/~shancock/Pe...19/bin/perltidy
Hey David, do you have a copy of the perltidy config from _PBP_? My
copy is at home...
I've never used it before and I thought his script would be a good one
to tidy. It doesn't compile... :p
-jp
| |
| DJ Stunks 2006-07-27, 6:57 pm |
| DJ Stunks wrote:
> usenet@DavidFilmer.com wrote:
>
> Hey David, do you have a copy of the perltidy config from _PBP_?
I found it on the web. It said it was reprinted with Pastor Conways
"kind permission" so I figure I'm ok to do the same thing:
# PBP .perltidyrc file
-l=78 # Max line width is 78 cols
-i=4 # Indent level is 4 cols
-ci=4 # Continuation indent is 4 cols
-st # Output to STDOUT
-se # Errors to STDERR
-vt=2 # Maximal vertical tightness
-cti=0 # No extra indentation for closing brackets
-pt=1 # Medium parenthesis tightness
-bt=1 # Medium brace tightness
-sbt=1 # Medium square bracket tightness
-bbt=1 # Medium block brace tightness
-nsfs # No space before semicolons
-nolq # Don't outdent long quoted strings
-wbb="% + - * / x != == >= <= =~ !~ < > | & >= < = **= += *= &= <<=
&& += -= /= |= >>= ||= .= %= ^= x=" # Break before all operators
-jp
| |
| usenet@DavidFilmer.com 2006-07-27, 6:57 pm |
| DJ Stunks wrote:
> Hey David, do you have a copy of the perltidy config from _PBP_?
No config file necessary...
perltidy -pbp
will give you the Conway style settings (which are also documented in
the perltidy perlfaq).
--
David Filmer (http://DavidFilmer.com)
| |
| DJ Stunks 2006-07-27, 6:57 pm |
|
usenet@DavidFilmer.com wrote:
> DJ Stunks wrote:
>
> No config file necessary...
>
> perltidy -pbp
>
> will give you the Conway style settings (which are also documented in
> the perltidy perlfaq).
nice. thanks.
-jp
| |
| Charles K. Clarkson 2006-07-27, 6:57 pm |
| Mike Martin wrote:
: I have the following code which should
:=20
: 1. Give user a choice of actions
: 2. Based on these go to the specified script
:=20
: I have the following issues
:=20
: 1. The Submit button needs clicking twice after selection
: 2. Only one value can be chosen, to choose another the form must be
: reloaded from scratch (ie: reload button does not work, only go etc)
:=20
: Any assistance appreciated
:=20
: Script follows
[snip]
The code does not compile. There is probably a syntax error on the
following line.
:
popup_menu(-name=3D>'select',-values=3D>[@select],-default=3D>$commands1{=
1}[0,-lab
els=3D>\%select);
BTW, is your space bar broken? White space (tabs, spaces, blank
lines, etc) used consistently can make programs easier to read and
maintain.
HTH,
Charles K. Clarkson
--=20
Mobile Homes Specialist
Free Market Advocate
Web Programmer
254 968-8328
Don't tread on my bandwidth. Trim your posts.
| |
| Charles K. Clarkson 2006-07-28, 9:56 pm |
| Mike Martin wrote:
: I have the following code which should
:
: 1. Give user a choice of actions
: 2. Based on these go to the specified script
:
: I have the following issues
:
: 1. The Submit button needs clicking twice after selection
The first time the script through the 'select' field is empty
and '' is passed into the form 'action' attribute. CGI.pm changes
this to the name of this script.
If '5' were chosen, the second time through the script the
'select' field is '5' and '/cgi-bin/finance.pl' is passed into
the form 'action' attribute.
You can remedy this by calling '/cgi-bin/finance.pl' from
the script rather then printing the form and then going to the
chosen script.
A better solution might include modules instead of scripts.
: 2. Only one value can be chosen, to choose another the form
: must be reloaded from scratch (ie: reload button does not
: work, only go etc)
That sounds like a browser caching problem. Search the CGI.pm
docs for 'cache' for details. You can also add a reset button for
the form.
HTH,
Charles K. Clarkson
--
Mobile Homes Specialist
Free Market Advocate
Web Programmer
254 968-8328
Don't tread on my bandwidth. Trim your posts.
| |
| Charles K. Clarkson 2006-07-28, 9:56 pm |
| Charles K. Clarkson wrote:
: The first time the script through the 'select' field is empty
Whoopsie!
The first time through the script the 'select' field is empty
| |
| Charles K. Clarkson 2006-07-30, 6:57 pm |
| Mike Martin wrote:
: I am trying not to go this route because I want to keep the
: subsidiary files as self-contained as possible
:
: There are four files at present which are around 600 lines,
: which I think is a sensible size. These all do a specific job
: which can be linked together.
:
: It would be nice to be able to distribute together or separate
I see. You could use a system call to the dispatch the scripts
from the first form. User and password could be sent on the
command line.
#!/usr/bin/perl -T
use strict;
use warnings;
use CGI::Carp 'fatalsToBrowser';
use CGI qw( header param :html :form );
if ( param('tasks') ) {
dispatch();
} else {
print task_form();
}
sub dispatch {
my %tasks = (
calendar => '',
contacts => '/cgi-bin/contacts.pl',
correspond => '',
filing => '',
file_manage => '/cgi-bin/finance.pl',
finance => '',
telephone => '',
timesheets => '/cgi-bin/timesheet.pl',
);
# Dispatch to script. *Not Tested*
foreach my $task ( param('tasks') ) {
next unless $tasks{$task};
system(
$tasks{$task},
param('user'),
param('pass'),
);
}
}
sub task_form {
my %tasks = (
calendar => 'Calendars',
contacts => 'Contacts',
correspond => 'Correspondence',
filing => 'Filing',
file_manage => 'File Management',
finance => 'Finance',
telephone => 'Telephone Logging',
timesheets => 'Timesheets',
);
return
header(),
start_html( -style => '/proj.css' ),
start_multipart_form(),
'user', br(),
textfield(
-name => 'user',
-size => 15,
), br(),
'password', br(),
password_field( -name => 'pass' ), br(), br(),
'Choose a task', br(),
scrolling_list(
-name => 'tasks',
-values => [ sort keys %tasks ],
-labels => \%tasks,
-multiple => 'true',
),
span(
{ -class => 'place_cmd' },
submit(
-name => 'act',
-value => 'Chooser',
)
),
br(),
end_form(),
end_html();
}
__END__
HTH,
Charles K. Clarkson
--
Mobile Homes Specialist
Free Market Advocate
Web Programmer
254 968-8328
Don't tread on my bandwidth. Trim your posts.
|
|
|
|
|