简体   繁体   中英

How do I substitute unseen name-value pairs (from radio buttons) in my CGI script?

Cross from PerlMonks, see bottom.

UPDATE: Perhaps the best way to do this is through HTML or JavaScript(I know nothing of these)?

Objective

After the whole code is run and an output is given, I'd like to provide a hyperlink to re-run the code, with the same search word, but different radio buttons pressed.

Here is a portion of my CGI script, related to the user input:

my $search_key  = param('query');
my $c_verb      = param('verb_only'); 
my $c_enabling  = param('enabling'); 
my $c_subject   = param('subject');
my $c_object    = param('object'); 
my $c_prep      = param('prep'); 
my $c_adj       = param('adjective');
my $c_modnoun   = param('modnoun');

my $category_id;


if ($c_verb eq 'on')
    {
    if ($c_enabling eq 'on')
        {$category_id = 'xcomp';}
    elsif ($c_subject eq 'on')
        {$category_id = 'subj';}
    elsif ($c_object eq 'on')
        {$category_id = 'obj';}
    elsif ($c_prep eq 'on')
        {$category_id = 'prep';}

I don't have access to the HTML, but from viewing the source code, all the $c_... have the form: <input type="checkbox" name="verb_only" onClick="ch...

The "unseen" in the title is referring to no appended name/tag value pairs, so I don't know what to change, Where can I find this information?

I was thinking of changing $c_enabling to $c_subject and another link to a case where it was as if $c_prep was chosen from the user. Is there a way to substitute the name-value pairs of that single param? (So user inputs options, runs, instead of going back to input different ones, just click hyperlink, because some options stay the same)

The URL of the form is like: http://concept.whatever.com/test.html and the output is at the URL: http://concept.whatever.com/cgi-bin/search2011.cgi

My attempt

See posted answer

UPDATE: I've tried `url(-query) but nothing was appended to the end...

Thanks for any advice. Let me know if this is not clear.

Original: http://www.perlmonks.org/?node_id=910616 .... Particularly applying this advice: http://www.perlmonks.org/?node_id=910630

If the method of the HTML is changed to GET instead of POST: <form name="search_option" action="http://localhost/cgi-bin/mytestsearch2011.cgi" method="get">

Then the tags can be viewed (I had to copy the source code and do this on my localhost to check them)

I was able to find out what tags and values to put, b/c get method. So here is the working code:

if ($category_id  eq "xcomp") {
    my $subjurl = "http://localhost/cgi-bin/mytestsearch2011.cgi?query=$search_key&verb_only=on&subject=on&exclude0=&exclude1=&exclude2=&exclude3=";
    print qq(<A HREF="$subjurl">Subject</A>\n)."    ";
    my $objurl = "http://localhost/cgi-bin/mytestsearch2011.cgi?query=$search_key&verb_only=on&object=on&exclude0=&exclude1=&exclude2=&exclude3=";
    print qq(<A HREF="$objurl">Object</A>\n)."  ";
    my $prepurl = "http://localhost/cgi-bin/mytestsearch2011.cgi?query=$search_key&verb_only=on&prep=on&exclude0=&exclude1=&exclude2=&exclude3=";
    print qq(<A HREF="$prepurl">Preposition</A>\n)."<br><br>";
}

elsif ($category_id  eq "subj") { ##List urls other than what is currently output:
    my $enablingurl = "http://localhost/cgi-bin/mytestsearch2011.cgi?query=$search_key&verb_only=on&enabling=on&exclude0=&exclude1=&exclude2=&exclude3=";
    print qq(<A HREF="$enablingurl">Enabling Function</A>\n)."  ";
...

I don't understand all the exclude tags, but that's okay...

UPDATE: This works with POST as well, I just needed to know all the tags that came after the URL. Thanks!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM