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_movie

The 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;

In reply to passing parameters to CGI script by dannoura

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.