dannoura has asked for the wisdom of the Perl Monks concerning the following question:
hi,
I have two CGI scripts which work with a database. The database has filenames as keys and descriptive tags (in an array) as values. The first script enables the user to search through the database for files, based on the tags. The list produced by the search has (for eac hit) a link to the second script with one parameter: the filename.
./add_remove_tags.pl?movie=some_movieThe second script produces a page which lists the tags for the file and enables the user (via a form) to add or remove tags. Each time the user presses the Add/Remove Tags button he'll end up on the same page, with the new tags (if any). The problem is that the script is not passing itself the movie parameter. It's my understanding that reinvoking the script should add the URL parameter to the others, but this doesn't work. I tried adding it via a hidden field, but that didn't work either. The code is below. Any suggestions?
#! c:/Perl/bin/Perl.exe -w use strict; use CGI; use CGI::Carp qw/fatalsToBrowser/; use DBM::Deep; use URI::Escape; my $q = CGI->new(); my %params = $q->Vars(); # Start page my $movie = uri_unescape($params{'movie'}); print $q->header( "text/html" ); print $q->start_html(-title => $movie); print $q->h1($movie); my $db = new DBM::Deep ("tag_test.db"); foreach my $param (keys %params) { if ($param eq 'add_tags') { # Add tags my @add_tags = split /,/, $params{$param}; push @{$db->{$movie}}, @add_tags; } elsif ($param ne 'Add/Remove Tags') { for (0..$#{$db->{$movie}}) { # Remove tags if ($param eq $db->{$movie}[$_]) { splice @{$db->{$movie}}, $_, 1; last; } } } } # Start form print $q->start_form(); print $q->textfield(-name => "add_tags"); print $q->table([map {$q->Tr( $q->checkbox(-name => $_))} @{$db->{$movie}}]); print $q->submit(-name => 'Add/Remove Tags'); print $q->end_form(); print $q->end_html;
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: passing parameters to CGI script
by rinceWind (Monsignor) on May 16, 2006 at 15:16 UTC | |
Re: passing parameters to CGI script
by ptum (Priest) on May 16, 2006 at 15:35 UTC | |
by dannoura (Pilgrim) on May 16, 2006 at 21:29 UTC |